Skip to content

The Unified and Autonomous Development Platform

feat: Support bean editor group descriptions

Robin Shend1f651de8712
diff --git a/server-core/src/main/java/io/onedev/server/annotation/Editable.java b/server-core/src/main/java/io/onedev/server/annotation/Editable.java
index cd77172dc9..4da27af62a 100644
--- a/server-core/src/main/java/io/onedev/server/annotation/Editable.java
+++ b/server-core/src/main/java/io/onedev/server/annotation/Editable.java
@@ -9,6 +9,12 @@ import java.lang.annotation.Target;
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Editable {
+ /**
+ * Property group name. The bean class may define a static, no-argument
+ * {@code Map<String, String> getGroupDescriptions()} method to supply descriptions
+ * displayed below group names in the bean editor. Map keys are the original
+ * group names; descriptions should handle translation if needed.
+ */
String group() default "";
String icon() default "";
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/BeanEditor.html b/server-core/src/main/java/io/onedev/server/web/editable/BeanEditor.html
index 969d7688ac..453641c15c 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/BeanEditor.html
+++ b/server-core/src/main/java/io/onedev/server/web/editable/BeanEditor.html
@@ -1,6 +1,12 @@
-<wicket:panel>
+<wicket:panel xmlns:wicket="http://www.w3.org/1999/xhtml">
<div wicket:id="groups" class="group bean-properties">
- <a wicket:id="toggle" class="toggle d-flex align-items-center"><span wicket:id="groupName" class="mr-3"></span> <wicket:svg href="arrow" class="icon ml-auto"/></a>
+ <a wicket:id="toggle" class="toggle d-flex align-items-center">
+ <span class="mr-3">
+ <span wicket:id="groupName" class="d-block"></span>
+ <span wicket:id="groupDescription" class="text-muted font-size-sm mt-1 d-block"></span>
+ </span>
+ <wicket:svg href="arrow" class="icon ml-auto"/>
+ </a>
<div>
<div wicket:id="properties" class="form-group">
<wicket:enclosure child="name">
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/BeanEditor.java b/server-core/src/main/java/io/onedev/server/web/editable/BeanEditor.java
index 96a4622bea..3f2fe0ee60 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/BeanEditor.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/BeanEditor.java
@@ -3,6 +3,7 @@ package io.onedev.server.web.editable;
import static io.onedev.server.web.translation.Translation._T;
import java.io.Serializable;
+import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -45,6 +46,7 @@ import io.onedev.server.util.HierarchicalContext;
import io.onedev.server.util.Path;
import io.onedev.server.util.PathNode;
import io.onedev.server.util.PathNode.Named;
+import io.onedev.server.util.ReflectionUtils;
import io.onedev.server.util.xstream.ObjectMap;
public class BeanEditor extends ValueEditor<Serializable> {
@@ -268,6 +270,11 @@ public class BeanEditor extends ValueEditor<Serializable> {
groupsView = new RepeatingView("groups");
add(groupsView);
+
+ Map<String, String> groupDescriptions = null;
+ var groupDescriptionsMethod = ReflectionUtils.findMethod(descriptor.getBeanClass(), "getGroupDescriptions");
+ if (groupDescriptionsMethod != null && Modifier.isStatic(groupDescriptionsMethod.getModifiers()))
+ groupDescriptions = ReflectionUtils.invokeStaticMethod(descriptor.getBeanClass(), "getGroupDescriptions");
for (Map.Entry<String, List<PropertyContext<Serializable>>> entry: propertyContexts.entrySet()) {
WebMarkupContainer groupContainer = new WebMarkupContainer(groupsView.newChildId());
@@ -283,6 +290,10 @@ public class BeanEditor extends ValueEditor<Serializable> {
groupName = _T(groupName);
toggleLink.add(new Label("groupName", groupName));
groupContainer.add(toggleLink);
+
+ String groupDescription = groupDescriptions != null ? groupDescriptions.get(entry.getKey()) : null;
+ toggleLink.add(new Label("groupDescription", groupDescription)
+ .setVisible(!entry.getKey().isEmpty() && groupDescription != null && !groupDescription.isBlank()));
RepeatingView propertiesView = new RepeatingView("properties");
groupContainer.add(propertiesView);
diff --git a/server-plugin/server-plugin-executor-serversandbox/src/main/java/io/onedev/server/plugin/executor/serversandbox/ServerSandboxExecutor.java b/server-plugin/server-plugin-executor-serversandbox/src/main/java/io/onedev/server/plugin/executor/serversandbox/ServerSandboxExecutor.java
index 22e53dbb71..b79e2d0f59 100644
--- a/server-plugin/server-plugin-executor-serversandbox/src/main/java/io/onedev/server/plugin/executor/serversandbox/ServerSandboxExecutor.java
+++ b/server-plugin/server-plugin-executor-serversandbox/src/main/java/io/onedev/server/plugin/executor/serversandbox/ServerSandboxExecutor.java
@@ -1,5 +1,7 @@
package io.onedev.server.plugin.executor.serversandbox;
+import static io.onedev.server.web.translation.Translation._T;
+
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
@@ -78,6 +80,11 @@ public class ServerSandboxExecutor extends JobExecutor implements SandboxAware,
private List<RegistryLogin> registryLogins = new ArrayList<>();
+ @SuppressWarnings("unused")
+ private static Map<String, String> getGroupDescriptions() {
+ return Map.of("Container Settings", _T("These settings are only used when running Docker containers inside the sandbox VM."));
+ }
+
@Editable(order=500, group="Container Settings", description="Whether or not to always pull images when running containers or building images "
+ "inside the sandbox. If disabled, cached images are used when available.")
public boolean isAlwaysPullContainerImage() {