The Unified and Autonomous Development Platform
fix: API: settings->contributedSettings: documentation does not match reality (and neither works) (OD-2242)
Robin Shenbe37d8fc32b9
diff --git a/server-core/src/main/java/io/onedev/server/annotation/Horizontal.java b/server-core/src/main/java/io/onedev/server/annotation/Horizontal.javadeleted file mode 100644index 4279a22a51..0000000000--- a/server-core/src/main/java/io/onedev/server/annotation/Horizontal.java+++ /dev/null@@ -1,12 +0,0 @@-package io.onedev.server.annotation;--import java.lang.annotation.ElementType;-import java.lang.annotation.Retention;-import java.lang.annotation.RetentionPolicy;-import java.lang.annotation.Target;--@Retention(RetentionPolicy.RUNTIME)-@Target({ElementType.TYPE, ElementType.METHOD})-public @interface Horizontal {--}diff --git a/server-core/src/main/java/io/onedev/server/annotation/Vertical.java b/server-core/src/main/java/io/onedev/server/annotation/Vertical.javaindex d8181d6a7d..0fbf9f47da 100644--- a/server-core/src/main/java/io/onedev/server/annotation/Vertical.java+++ b/server-core/src/main/java/io/onedev/server/annotation/Vertical.java@@ -10,4 +10,3 @@ import java.lang.annotation.Target;public @interface Vertical {}-\ No newline at end of filediff --git a/server-core/src/main/java/io/onedev/server/data/migration/DataMigrator.java b/server-core/src/main/java/io/onedev/server/data/migration/DataMigrator.javaindex 49596ec87b..c880311d2c 100644--- a/server-core/src/main/java/io/onedev/server/data/migration/DataMigrator.java+++ b/server-core/src/main/java/io/onedev/server/data/migration/DataMigrator.java@@ -7280,4 +7280,30 @@ public class DataMigrator {private void migrate184(File dataDir, Stack<Integer> versions) {}+ private void migrate185(File dataDir, Stack<Integer> versions) {+ for (File file : dataDir.listFiles()) {+ if (file.getName().startsWith("Projects.xml")) {+ VersionedXmlDoc dom = VersionedXmlDoc.fromFile(file);+ for (Element element : dom.getRootElement().elements()) {+ for (var contributedSettingElement: element.element("contributedSettings").elements()) {+ var className = contributedSettingElement.elementText("string").trim();+ if (className.contains("NtfyNotificationSetting") || className.contains("SlackNotificationSetting")+ || className.contains("DiscordNotificationSetting")) {+ for (var wrapperElement: contributedSettingElement.elements().get(1).element("notifications").elements()) {+ wrapperElement.setName(wrapperElement.getName().replace("ChannelNotificationWrapper", "ChannelNotification"));+ var notificationElement = wrapperElement.element("channelNotification");+ for (var childElement: notificationElement.elements()) {+ childElement.detach();+ wrapperElement.add(childElement);+ }+ notificationElement.detach();+ }+ }+ }+ }+ dom.writeToFile(file, false);+ }+ }+ }+}\ No newline at end of filediff --git a/server-core/src/main/java/io/onedev/server/entitymanager/SettingManager.java b/server-core/src/main/java/io/onedev/server/entitymanager/SettingManager.javaindex 4cd046758a..cddce4e513 100644--- a/server-core/src/main/java/io/onedev/server/entitymanager/SettingManager.java+++ b/server-core/src/main/java/io/onedev/server/entitymanager/SettingManager.java@@ -164,8 +164,9 @@ public interface SettingManager extends EntityManager<Setting> {@Nullable<T extends ContributedAdministrationSetting> T getContributedSetting(Class<T> settingClass);- void saveContributedSetting(Class<? extends ContributedAdministrationSetting> settingClass,- @Nullable ContributedAdministrationSetting setting);+ void saveContributedSetting(ContributedAdministrationSetting setting);++ void removeContributedSetting(Class<? extends ContributedAdministrationSetting> settingClass);Collection<String> getUndefinedIssueFields();diff --git a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSettingManager.java b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSettingManager.javaindex d6381359e4..3f34220426 100644--- a/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSettingManager.java+++ b/server-core/src/main/java/io/onedev/server/entitymanager/impl/DefaultSettingManager.java@@ -378,25 +378,31 @@ public class DefaultSettingManager extends BaseEntityManager<Setting>@Nullable@SuppressWarnings("unchecked")public <T extends ContributedAdministrationSetting> T getContributedSetting(Class<T> settingClass) {- T contributedSetting = (T) getContributedSettings().get(settingClass.getName());- if (contributedSetting == null) {+ T setting = (T) getContributedSettings().get(settingClass.getName());+ if (setting == null) {try {T value = settingClass.getDeclaredConstructor().newInstance();if (OneDev.getInstance(Validator.class).validate(value).isEmpty())- contributedSetting = value;+ setting = value;} catch (InstantiationException | IllegalAccessException | IllegalArgumentException| InvocationTargetException | NoSuchMethodException | SecurityException e) {throw new RuntimeException(e);}}-- return contributedSetting;+ return setting;}- public void saveContributedSetting(Class<? extends ContributedAdministrationSetting> settingClass,- @Nullable ContributedAdministrationSetting setting) {- Map<String, ContributedAdministrationSetting> contributedSettings = getContributedSettings();- contributedSettings.put(settingClass.getName(), setting);+ @Override+ public void saveContributedSetting(ContributedAdministrationSetting setting) {+ var contributedSettings = getContributedSettings();+ contributedSettings.put(setting.getClass().getName(), setting);+ saveSetting(Key.CONTRIBUTED_SETTINGS, (Serializable) contributedSettings);+ }++ @Override+ public void removeContributedSetting(Class<? extends ContributedAdministrationSetting> settingClass) {+ var contributedSettings = getContributedSettings();+ contributedSettings.remove(settingClass.getName());saveSetting(Key.CONTRIBUTED_SETTINGS, (Serializable) contributedSettings);}diff --git a/server-core/src/main/java/io/onedev/server/model/Project.java b/server-core/src/main/java/io/onedev/server/model/Project.javaindex 6ffd38c9ab..4a9e9032d0 100644--- a/server-core/src/main/java/io/onedev/server/model/Project.java+++ b/server-core/src/main/java/io/onedev/server/model/Project.java@@ -1650,7 +1650,11 @@ public class Project extends AbstractEntity implements LabelSupport<ProjectLabelpublic LinkedHashMap<String, ContributedProjectSetting> getContributedSettings() {return contributedSettings;}-++ public void setContributedSettings(LinkedHashMap<String, ContributedProjectSetting> contributedSettings) {+ this.contributedSettings = contributedSettings;+ }+@Nullable@SuppressWarnings("unchecked")public <T extends ContributedProjectSetting> T getContributedSetting(Class<T> settingClass) {@@ -1671,7 +1675,10 @@ public class Project extends AbstractEntity implements LabelSupport<ProjectLabelpublic void setContributedSetting(Class<? extends ContributedProjectSetting> settingClass,@Nullable ContributedProjectSetting setting) {- contributedSettings.put(settingClass.getName(), setting);+ if (setting != null)+ contributedSettings.put(settingClass.getName(), setting);+ else+ contributedSettings.remove(settingClass.getName());}public String calcPath() {diff --git a/server-core/src/main/java/io/onedev/server/model/support/channelnotification/ChannelNotificationSetting.java b/server-core/src/main/java/io/onedev/server/model/support/channelnotification/ChannelNotificationSetting.javaindex f27ebb98fe..4c50672edf 100644--- a/server-core/src/main/java/io/onedev/server/model/support/channelnotification/ChannelNotificationSetting.java+++ b/server-core/src/main/java/io/onedev/server/model/support/channelnotification/ChannelNotificationSetting.java@@ -8,6 +8,7 @@ import java.util.Set;import javax.validation.ConstraintValidatorContext;import javax.validation.constraints.NotNull;+import io.onedev.server.annotation.Vertical;import io.onedev.server.validation.Validatable;import io.onedev.server.annotation.ClassValidating;import io.onedev.server.annotation.Editable;@@ -19,25 +20,26 @@ public class ChannelNotificationSetting implements ContributedProjectSetting, Vaprivate static final long serialVersionUID = 1L;- private List<ChannelNotificationWrapper> notifications = new ArrayList<>();+ private List<ChannelNotification> notifications = new ArrayList<>();@Editable+ @Vertical@OmitName@NotNull- public List<ChannelNotificationWrapper> getNotifications() {+ public List<ChannelNotification> getNotifications() {return notifications;}- public void setNotifications(List<ChannelNotificationWrapper> notifications) {+ public void setNotifications(List<ChannelNotification> notifications) {this.notifications = notifications;}@Overridepublic boolean isValid(ConstraintValidatorContext context) {Set<String> webhookUrls = new HashSet<>();- for (ChannelNotificationWrapper notification: notifications) {- if (notification.getChannelNotification().getWebhookUrl() != null- && !webhookUrls.add(notification.getChannelNotification().getWebhookUrl())) {+ for (ChannelNotification notification: notifications) {+ if (notification.getWebhookUrl() != null+ && !webhookUrls.add(notification.getWebhookUrl())) {context.disableDefaultConstraintViolation();context.buildConstraintViolationWithTemplate("Duplicate webhook url found").addConstraintViolation();return false;diff --git a/server-core/src/main/java/io/onedev/server/model/support/channelnotification/ChannelNotificationWrapper.java b/server-core/src/main/java/io/onedev/server/model/support/channelnotification/ChannelNotificationWrapper.javadeleted file mode 100644index b292a2a234..0000000000--- a/server-core/src/main/java/io/onedev/server/model/support/channelnotification/ChannelNotificationWrapper.java+++ /dev/null@@ -1,28 +0,0 @@-package io.onedev.server.model.support.channelnotification;--import java.io.Serializable;--import javax.validation.constraints.NotNull;--import io.onedev.server.annotation.Editable;-import io.onedev.server.annotation.OmitName;--@Editable-public class ChannelNotificationWrapper implements Serializable {-- private static final long serialVersionUID = 1L;-- private ChannelNotification channelNotification = new ChannelNotification();-- @Editable- @OmitName- @NotNull- public ChannelNotification getChannelNotification() {- return channelNotification;- }-- public void setChannelNotification(ChannelNotification channelNotification) {- this.channelNotification = channelNotification;- }--}\ No newline at end of filediff --git a/server-core/src/main/java/io/onedev/server/model/support/code/BranchProtection.java b/server-core/src/main/java/io/onedev/server/model/support/code/BranchProtection.javaindex 0f09b84ebb..6ba5ac610b 100644--- a/server-core/src/main/java/io/onedev/server/model/support/code/BranchProtection.java+++ b/server-core/src/main/java/io/onedev/server/model/support/code/BranchProtection.java@@ -5,7 +5,10 @@ import com.google.common.base.Splitter;import io.onedev.commons.codeassist.InputSuggestion;import io.onedev.commons.utils.match.PathMatcher;import io.onedev.server.OneDev;-import io.onedev.server.annotation.*;+import io.onedev.server.annotation.Editable;+import io.onedev.server.annotation.JobChoice;+import io.onedev.server.annotation.Patterns;+import io.onedev.server.annotation.ShowCondition;import io.onedev.server.buildspec.BuildSpec;import io.onedev.server.entitymanager.BuildManager;import io.onedev.server.git.service.GitService;@@ -35,7 +38,6 @@ import static java.util.regex.Pattern.CASE_INSENSITIVE;import static java.util.regex.Pattern.UNICODE_CHARACTER_CLASS;@Editable-@Horizontalpublic class BranchProtection implements Serializable {private static final long serialVersionUID = 1L;diff --git a/server-core/src/main/java/io/onedev/server/model/support/code/TagProtection.java b/server-core/src/main/java/io/onedev/server/model/support/code/TagProtection.javaindex 1ada449eeb..205b54909a 100644--- a/server-core/src/main/java/io/onedev/server/model/support/code/TagProtection.java+++ b/server-core/src/main/java/io/onedev/server/model/support/code/TagProtection.java@@ -1,14 +1,13 @@package io.onedev.server.model.support.code;import io.onedev.commons.codeassist.InputSuggestion;+import io.onedev.server.annotation.Editable;+import io.onedev.server.annotation.Patterns;import io.onedev.server.model.Project;import io.onedev.server.util.patternset.PatternSet;import io.onedev.server.util.usage.Usage;import io.onedev.server.util.usermatch.Anyone;import io.onedev.server.util.usermatch.UserMatch;-import io.onedev.server.annotation.Editable;-import io.onedev.server.annotation.Horizontal;-import io.onedev.server.annotation.Patterns;import io.onedev.server.web.util.SuggestionUtils;import javax.validation.constraints.NotEmpty;@@ -17,7 +16,6 @@ import java.util.ArrayList;import java.util.List;@Editable-@Horizontalpublic class TagProtection implements Serializable {private static final long serialVersionUID = 1L;diff --git a/server-core/src/main/java/io/onedev/server/notification/ChannelNotificationManager.java b/server-core/src/main/java/io/onedev/server/notification/ChannelNotificationManager.javaindex 23984f24f5..fcb87356bd 100644--- a/server-core/src/main/java/io/onedev/server/notification/ChannelNotificationManager.java+++ b/server-core/src/main/java/io/onedev/server/notification/ChannelNotificationManager.java@@ -14,7 +14,6 @@ import io.onedev.server.git.GitUtils;import io.onedev.server.model.*;import io.onedev.server.model.support.channelnotification.ChannelNotification;import io.onedev.server.model.support.channelnotification.ChannelNotificationSetting;-import io.onedev.server.model.support.channelnotification.ChannelNotificationWrapper;import io.onedev.server.persistence.annotation.Sessional;import io.onedev.server.util.ReflectionUtils;import org.apache.commons.lang3.StringUtils;@@ -147,8 +146,8 @@ public abstract class ChannelNotificationManager<T extends ChannelNotificationSeMap<String, ChannelNotification> notifications = new HashMap<>();do {T setting = project.getContributedSetting(settingClass);- for (ChannelNotificationWrapper wrapper : setting.getNotifications())- notifications.putIfAbsent(wrapper.getChannelNotification().getWebhookUrl(), wrapper.getChannelNotification());+ for (var notification : setting.getNotifications())+ notifications.putIfAbsent(notification.getWebhookUrl(), notification);project = project.getParent();} while (project != null);diff --git a/server-core/src/main/java/io/onedev/server/rest/resource/ProjectResource.java b/server-core/src/main/java/io/onedev/server/rest/resource/ProjectResource.javaindex 638380b5b2..9b39a53db4 100644--- a/server-core/src/main/java/io/onedev/server/rest/resource/ProjectResource.java+++ b/server-core/src/main/java/io/onedev/server/rest/resource/ProjectResource.java@@ -109,7 +109,7 @@ public class ProjectResource {setting.namedCommitQueries = project.getNamedCommitQueries();setting.pullRequestSetting = project.getPullRequestSetting();setting.webHooks = project.getWebHooks();- setting.contributedSettings = project.getContributedSettings();+ setting.contributedSettings.addAll(project.getContributedSettings().values());return setting;}@@ -314,6 +314,10 @@ public class ProjectResource {project.setNamedCommitQueries(setting.namedCommitQueries);project.setPullRequestSetting(setting.pullRequestSetting);project.setWebHooks(setting.webHooks);+ var contributedSettings = new LinkedHashMap<String, ContributedProjectSetting>();+ for (var contributedSetting: setting.getContributedSettings())+ contributedSettings.put(contributedSetting.getClass().getName(), contributedSetting);+ project.setContributedSettings(contributedSettings);projectManager.update(project);return Response.ok().build();}@@ -377,7 +381,7 @@ public class ProjectResource {private ArrayList<WebHook> webHooks = new ArrayList<>();- private LinkedHashMap<String, ContributedProjectSetting> contributedSettings = new LinkedHashMap<>();+ private ArrayList<ContributedProjectSetting> contributedSettings = new ArrayList<>();public ArrayList<BranchProtection> getBranchProtections() {return branchProtections;@@ -451,11 +455,11 @@ public class ProjectResource {this.webHooks = webHooks;}- public LinkedHashMap<String, ContributedProjectSetting> getContributedSettings() {+ public ArrayList<ContributedProjectSetting> getContributedSettings() {return contributedSettings;}- public void setContributedSettings(LinkedHashMap<String, ContributedProjectSetting> contributedSettings) {+ public void setContributedSettings(ArrayList<ContributedProjectSetting> contributedSettings) {this.contributedSettings = contributedSettings;}diff --git a/server-core/src/main/java/io/onedev/server/rest/resource/SettingResource.java b/server-core/src/main/java/io/onedev/server/rest/resource/SettingResource.javaindex d7f1c28c88..3df2d50d85 100644--- a/server-core/src/main/java/io/onedev/server/rest/resource/SettingResource.java+++ b/server-core/src/main/java/io/onedev/server/rest/resource/SettingResource.java@@ -20,8 +20,7 @@ import javax.validation.constraints.NotNull;import javax.ws.rs.*;import javax.ws.rs.core.MediaType;import javax.ws.rs.core.Response;-import java.util.List;-import java.util.Map;+import java.util.*;@Api(order=10000)@Path("/settings")@@ -175,10 +174,10 @@ public class SettingResource {@Api(order=1450)@Path("/contributed-settings")@GET- public Map<String, ContributedAdministrationSetting> getContributedSettings() {+ public List<ContributedAdministrationSetting> getContributedSettings() {if (!SecurityUtils.isAdministrator())throw new UnauthorizedException();- return settingManager.getContributedSettings();+ return new ArrayList<>(settingManager.getContributedSettings().values());}@Api(order=1500)@@ -339,10 +338,13 @@ public class SettingResource {@Api(order=2800)@Path("/contributed-settings")@POST- public Response setContributedSettings(@NotNull Map<String, ContributedAdministrationSetting> contributedSettings) {+ public Response setContributedSettings(@NotNull List<ContributedAdministrationSetting> contributedSettings) {if (!SecurityUtils.isAdministrator())throw new UnauthorizedException();- settingManager.saveContributedSettings(contributedSettings);+ var settingMap = new HashMap<String, ContributedAdministrationSetting>();+ for (var setting: contributedSettings)+ settingMap.put(setting.getClass().getName(), setting);+ settingManager.saveContributedSettings(settingMap);return Response.ok().build();}diff --git a/server-core/src/main/java/io/onedev/server/util/jackson/ObjectMapperProvider.java b/server-core/src/main/java/io/onedev/server/util/jackson/ObjectMapperProvider.javaindex f7c59a4175..e218c69046 100644--- a/server-core/src/main/java/io/onedev/server/util/jackson/ObjectMapperProvider.java+++ b/server-core/src/main/java/io/onedev/server/util/jackson/ObjectMapperProvider.java@@ -1,9 +1,7 @@package io.onedev.server.util.jackson;import java.io.Serializable;-import java.util.Collection;-import java.util.Map;-import java.util.Set;+import java.util.*;import java.util.stream.Collectors;import javax.inject.Inject;@@ -29,16 +27,29 @@ import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;import com.fasterxml.jackson.databind.util.StdDateFormat;import io.onedev.commons.loader.ImplementationRegistry;+import io.onedev.server.web.page.layout.AdministrationSettingContribution;+import io.onedev.server.web.page.layout.ContributedAdministrationSetting;+import io.onedev.server.web.page.project.setting.ContributedProjectSetting;+import io.onedev.server.web.page.project.setting.ProjectSettingContribution;@Singletonpublic class ObjectMapperProvider implements Provider<ObjectMapper> {private final Set<ObjectMapperConfigurator> configurators;-++ private final Set<ProjectSettingContribution> projectSettingContributions;++ private final Set<AdministrationSettingContribution> administrationSettingContributions;+private final ImplementationRegistry implementationRegistry;@Inject- public ObjectMapperProvider(ImplementationRegistry implementationRegistry, Set<ObjectMapperConfigurator> configurators) {+ public ObjectMapperProvider(Set<ProjectSettingContribution> projectSettingContributions,+ Set<AdministrationSettingContribution> administrationSettingContributions,+ ImplementationRegistry implementationRegistry,+ Set<ObjectMapperConfigurator> configurators) {+ this.projectSettingContributions = projectSettingContributions;+ this.administrationSettingContributions = administrationSettingContributions;this.implementationRegistry = implementationRegistry;this.configurators = configurators;}@@ -58,6 +69,21 @@ public class ObjectMapperProvider implements Provider<ObjectMapper> {}private Collection<NamedType> getSubTypes(JavaType baseType) {+ if (baseType.getRawClass() == ContributedProjectSetting.class) {+ List<NamedType> subTypes = new ArrayList<>();+ for (var contribution: projectSettingContributions) {+ for (var settingClass: contribution.getSettingClasses())+ subTypes.add(new NamedType(settingClass));+ }+ return subTypes;+ } else if (baseType.getRawClass() == ContributedAdministrationSetting.class) {+ List<NamedType> subTypes = new ArrayList<>();+ for (var contribution: administrationSettingContributions) {+ for (var settingClass: contribution.getSettingClasses())+ subTypes.add(new NamedType(settingClass));+ }+ return subTypes;+ }return implementationRegistry.getImplementations(baseType.getRawClass()).stream().map(it->new NamedType(it))diff --git a/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListEditSupport.javaindex 724815720b..fae80da4f9 100644--- a/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListEditSupport.java+++ b/server-core/src/main/java/io/onedev/server/web/editable/beanlist/BeanListEditSupport.java@@ -4,6 +4,7 @@ import java.io.Serializable;import java.lang.reflect.AnnotatedElement;import java.util.List;+import io.onedev.server.annotation.Vertical;import org.apache.wicket.Component;import org.apache.wicket.model.IModel;@@ -25,6 +26,7 @@ public class BeanListEditSupport implements EditSupport {if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());if (elementClass != null && ClassUtils.isConcrete(elementClass)+ && descriptor.getPropertyGetter().getAnnotation(Vertical.class) == null&& elementClass.getAnnotation(Editable.class) != null) {return new PropertyContext<List<Serializable>>(descriptor) {diff --git a/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListEditSupport.java b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListEditSupport.javanew file mode 100644index 0000000000..515ba2207f--- /dev/null+++ b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListEditSupport.java@@ -0,0 +1,66 @@+package io.onedev.server.web.editable.verticalbeanlist;++import io.onedev.commons.utils.ClassUtils;+import io.onedev.server.annotation.Editable;+import io.onedev.server.annotation.Vertical;+import io.onedev.server.util.ReflectionUtils;+import io.onedev.server.web.editable.*;+import org.apache.wicket.Component;+import org.apache.wicket.model.IModel;++import java.io.Serializable;+import java.lang.reflect.AnnotatedElement;+import java.util.List;++@SuppressWarnings("serial")+public class VerticalBeanListEditSupport implements EditSupport {++ @Override+ public PropertyContext<?> getEditContext(PropertyDescriptor descriptor) {+ if (List.class.isAssignableFrom(descriptor.getPropertyClass())) {+ Class<?> elementClass = ReflectionUtils.getCollectionElementClass(descriptor.getPropertyGetter().getGenericReturnType());+ if (elementClass != null && ClassUtils.isConcrete(elementClass)+ && descriptor.getPropertyGetter().getAnnotation(Vertical.class) != null+ && elementClass.getAnnotation(Editable.class) != null) {+ return new PropertyContext<List<Serializable>>(descriptor) {++ @Override+ public PropertyViewer renderForView(String componentId, final IModel<List<Serializable>> model) {+ return new PropertyViewer(componentId, descriptor) {++ @Override+ protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {+ if (model.getObject() != null) {+ return new VerticalBeanListPropertyViewer(id, propertyDescriptor, model.getObject());+ } else {+ return new EmptyValueLabel(id) {++ @Override+ protected AnnotatedElement getElement() {+ return propertyDescriptor.getPropertyGetter();+ }++ };+ }+ }++ };+ }++ @Override+ public PropertyEditor<List<Serializable>> renderForEdit(String componentId, IModel<List<Serializable>> model) {+ return new VerticalBeanListPropertyEditor(componentId, descriptor, model);+ }++ };+ }+ }+ return null;+ }++ @Override+ public int getPriority() {+ return DEFAULT_PRIORITY;+ }++}diff --git a/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyEditor.html b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyEditor.htmlnew file mode 100644index 0000000000..9e03a7f915--- /dev/null+++ b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyEditor.html@@ -0,0 +1,26 @@+<wicket:panel>+ <div class="vertical-bean-list">+ <table wicket:id="table">+ <tbody>+ <tr wicket:id="elements">+ <td class="actions minimum">+ <wicket:svg href="grip" class="icon drag-indicator"/>+ </td>+ <td>+ <div wicket:id="elementEditor"></div>+ <div wicket:id="feedback"></div>+ </td>+ <td class="actions minimum">+ <a wicket:id="deleteElement" class="btn btn-icon btn-light btn-hover-danger" title="Delete this"><wicket:svg href="trash" class="icon delete"/></a>+ </td>+ </tr>+ </tbody>+ <tfoot wicket:id="noRecords">+ <tr>+ <td colspan="3">Unspecified</td>+ </tr>+ </tfoot>+ </table>+ <div class="foot"><a wicket:id="addElement" title="Add new" class="add-element btn btn-light btn-hover-primary btn-block"><wicket:svg href="plus" class="icon"></wicket:svg></a></div>+ </div>+</wicket:panel>\ No newline at end of filediff --git a/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyEditor.java b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyEditor.javanew file mode 100644index 0000000000..49eb2f8ea2--- /dev/null+++ b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyEditor.java@@ -0,0 +1,277 @@+package io.onedev.server.web.editable.verticalbeanlist;++import io.onedev.commons.utils.ClassUtils;+import io.onedev.server.annotation.ExcludedProperties;+import io.onedev.server.util.Path;+import io.onedev.server.util.PathNode;+import io.onedev.server.util.ReflectionUtils;+import io.onedev.server.web.behavior.NoRecordsBehavior;+import io.onedev.server.web.behavior.sortable.SortBehavior;+import io.onedev.server.web.behavior.sortable.SortPosition;+import io.onedev.server.web.editable.*;+import org.apache.wicket.Component;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.markup.html.form.AjaxButton;+import org.apache.wicket.event.IEvent;+import org.apache.wicket.feedback.FencedFeedbackPanel;+import org.apache.wicket.markup.ComponentTag;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.form.Form;+import org.apache.wicket.markup.repeater.RepeatingView;+import org.apache.wicket.model.IModel;+import org.apache.wicket.util.convert.ConversionException;++import java.io.Serializable;+import java.lang.reflect.InvocationTargetException;+import java.util.*;++import static java.util.Arrays.asList;++@SuppressWarnings("serial")+public class VerticalBeanListPropertyEditor extends PropertyEditor<List<Serializable>> {++ private Class<?> elementClass;++ private RepeatingView rows;++ private WebMarkupContainer noRecords;++ private Set<String> excludedProperties = new HashSet<>();++ public VerticalBeanListPropertyEditor(String id, PropertyDescriptor propertyDescriptor,+ IModel<List<Serializable>> model) {+ super(id, propertyDescriptor, model);++ elementClass = ReflectionUtils.getCollectionElementClass(propertyDescriptor.getPropertyGetter().getGenericReturnType());+ ExcludedProperties excludedPropertiesAnnotation =+ descriptor.getPropertyGetter().getAnnotation(ExcludedProperties.class);+ if (excludedPropertiesAnnotation != null)+ excludedProperties.addAll(asList(excludedPropertiesAnnotation.value()));+ }++ @SuppressWarnings("unchecked")+ private List<Serializable> newList() {+ if (ClassUtils.isConcrete(getDescriptor().getPropertyClass())) {+ try {+ return (List<Serializable>) getDescriptor().getPropertyClass().getDeclaredConstructor().newInstance();+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException+ | InvocationTargetException | NoSuchMethodException | SecurityException e) {+ throw new RuntimeException(e);+ }+ } else {+ return new ArrayList<>();+ }+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ List<Serializable> list = getModelObject();+ if (list == null)+ list = newList();++ WebMarkupContainer table = new WebMarkupContainer("table") {++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ if (rows.size() == 0)+ NoRecordsBehavior.decorate(tag);+ }++ };+ add(table);++ rows = new RepeatingView("elements");+ table.add(rows);++ for (Serializable element: list)+ addRow(element);++ add(new AjaxButton("addElement") {++ @SuppressWarnings("deprecation")+ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);+ markFormDirty(target);++ Component lastRow;+ if (rows.size() != 0)+ lastRow = rows.get(rows.size() - 1);+ else+ lastRow = null;++ Component newRow = addRow(newElement());+ String script = String.format("$('<tr id=\"%s\"></tr>')", newRow.getMarkupId());+ if (lastRow != null)+ script += ".insertAfter('#" + lastRow.getMarkupId() + "');";+ else+ script += ".appendTo('#" + VerticalBeanListPropertyEditor.this.getMarkupId() + ">div>table>tbody');";++ target.prependJavaScript(script);+ target.add(newRow);+ target.add(noRecords);+ if (rows.size() == 1) {+ target.appendJavaScript(String.format("$('#%s>div>table').removeClass('%s');",+ VerticalBeanListPropertyEditor.this.getMarkupId(), NoRecordsBehavior.CSS_CLASS));+ }++ onPropertyUpdating(target);+ }++ }.setDefaultFormProcessing(false));++ table.add(noRecords = new WebMarkupContainer("noRecords") {++ @Override+ protected void onConfigure() {+ super.onConfigure();+ setVisible(rows.size() == 0);+ }++ });+ noRecords.setOutputMarkupPlaceholderTag(true);++ add(new SortBehavior() {++ @SuppressWarnings("deprecation")+ @Override+ protected void onSort(AjaxRequestTarget target, SortPosition from, SortPosition to) {+ markFormDirty(target);++ /*+ List<Component> children = new ArrayList<>();+ for (Component child: rows)+ children.add(child);++ Component fromChild = children.remove(from.getItemIndex());+ children.add(to.getItemIndex(), fromChild);++ rows.removeAll();+ for (Component child: children)+ rows.add(child);+ */++ // Do not use code above as removing components outside of a container and add again+ // can cause the fenced feedback panel not functioning properly+ int fromIndex = from.getItemIndex();+ int toIndex = to.getItemIndex();+ if (fromIndex < toIndex) {+ for (int i=0; i<toIndex-fromIndex; i++)+ rows.swap(fromIndex+i, fromIndex+i+1);+ } else {+ for (int i=0; i<fromIndex-toIndex; i++)+ rows.swap(fromIndex-i, fromIndex-i-1);+ }+ onPropertyUpdating(target);+ }++ }.sortable("tbody"));++ add(validatable -> {+ var index = 0;+ for (var element: validatable.getValue()) {+ if (element == null)+ rows.get(index).error("must not be null");+ index++;+ }+ });++ setOutputMarkupId(true);+ }++ @Override+ public void onEvent(IEvent<?> event) {+ super.onEvent(event);++ if (event.getPayload() instanceof PropertyUpdating) {+ event.stop();+ onPropertyUpdating(((PropertyUpdating)event.getPayload()).getHandler());+ }+ }++ private WebMarkupContainer addRow(Serializable element) {+ WebMarkupContainer row = new WebMarkupContainer(rows.newChildId());+ row.setOutputMarkupId(true);+ rows.add(row);++ row.add(BeanContext.edit("elementEditor", element, excludedProperties, true));+ row.add(new FencedFeedbackPanel("feedback", row));++ row.add(new AjaxButton("deleteElement") {++ @Override+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {+ super.onSubmit(target, form);+ markFormDirty(target);+ target.appendJavaScript(String.format("$('#%s').remove();", row.getMarkupId()));+ rows.remove(row);+ target.add(noRecords);++ if (rows.size() == 0) {+ target.appendJavaScript(String.format("$('#%s>div>table').addClass('%s');",+ VerticalBeanListPropertyEditor.this.getMarkupId(), NoRecordsBehavior.CSS_CLASS));+ }++ onPropertyUpdating(target);+ }++ }.setDefaultFormProcessing(false));++ return row;+ }++ @SuppressWarnings("unchecked")+ private BeanEditor getElementEditorAtRow(int index) {+ int currentIndex = 0;+ Iterator<Component> it = rows.iterator();+ Component row = it.next();+ while (currentIndex++ < index) {+ row = it.next();+ }+ return (BeanEditor) row.get("elementEditor");+ }++ @Override+ public void error(PathNode propertyNode, Path pathInProperty, String errorMessage) {+ int index = ((PathNode.Indexed) propertyNode).getIndex();+ PathNode.Named named = (PathNode.Named) pathInProperty.takeNode();+ if (named != null)+ getElementEditorAtRow(index).error(named, pathInProperty, errorMessage);+ else+ rows.get(index).error(errorMessage);+ }++ @Override+ protected String getInvalidClass() {+ return null;+ }++ private Serializable newElement() {+ try {+ return (Serializable) elementClass.getDeclaredConstructor().newInstance();+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException+ | InvocationTargetException | NoSuchMethodException | SecurityException e) {+ throw new RuntimeException(e);+ }+ }++ @Override+ protected List<Serializable> convertInputToValue() throws ConversionException {+ List<Serializable> newList = newList();++ for (Component row: rows) {+ BeanEditor elementEditor = (BeanEditor) row.get("elementEditor");+ newList.add(elementEditor.getConvertedInput());+ }+ return newList;+ }++ @Override+ public boolean needExplicitSubmit() {+ return true;+ }++}diff --git a/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyViewer.html b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyViewer.htmlnew file mode 100644index 0000000000..a58b10f8a9--- /dev/null+++ b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyViewer.html@@ -0,0 +1,16 @@+<wicket:panel>+ <table wicket:id="table" class="vertical-bean-list">+ <tbody>+ <tr wicket:id="elements">+ <td>+ <div wicket:id="beanViewer"></div>+ </td>+ </tr>+ </tbody>+ <tfoot wicket:id="noRecords">+ <tr>+ <td>Unspecified</td>+ </tr>+ </tfoot>+ </table>+</wicket:panel>\ No newline at end of filediff --git a/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyViewer.java b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyViewer.javanew file mode 100644index 0000000000..1272af2dd2--- /dev/null+++ b/server-core/src/main/java/io/onedev/server/web/editable/verticalbeanlist/VerticalBeanListPropertyViewer.java@@ -0,0 +1,68 @@+package io.onedev.server.web.editable.verticalbeanlist;++import io.onedev.server.annotation.ExcludedProperties;+import io.onedev.server.web.behavior.NoRecordsBehavior;+import io.onedev.server.web.editable.BeanContext;+import io.onedev.server.web.editable.PropertyDescriptor;+import org.apache.wicket.markup.ComponentTag;+import org.apache.wicket.markup.html.WebMarkupContainer;+import org.apache.wicket.markup.html.list.ListItem;+import org.apache.wicket.markup.html.list.ListView;+import org.apache.wicket.markup.html.panel.Panel;++import java.io.Serializable;+import java.util.HashSet;+import java.util.List;+import java.util.Set;++import static java.util.Arrays.asList;++@SuppressWarnings("serial")+public class VerticalBeanListPropertyViewer extends Panel {++ private final List<Serializable> elements;++ private final Set<String> excludedProperties = new HashSet<>();++ public VerticalBeanListPropertyViewer(String id, PropertyDescriptor descriptor, List<Serializable> elements) {+ super(id);+ this.elements = elements;++ ExcludedProperties excludedPropertiesAnnotation =+ descriptor.getPropertyGetter().getAnnotation(ExcludedProperties.class);+ if (excludedPropertiesAnnotation != null)+ excludedProperties.addAll(asList(excludedPropertiesAnnotation.value()));+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ WebMarkupContainer table = new WebMarkupContainer("table") {++ @Override+ protected void onComponentTag(ComponentTag tag) {+ super.onComponentTag(tag);+ if (elements.isEmpty())+ NoRecordsBehavior.decorate(tag);+ }++ };+ add(table);++ table.add(new ListView<>("elements", elements) {++ @Override+ protected void populateItem(ListItem<Serializable> item) {+ var value = item.getModelObject();+ item.add(BeanContext.view("beanViewer", value, excludedProperties, true));+ }++ });++ WebMarkupContainer noRecords = new WebMarkupContainer("noRecords");+ noRecords.setVisible(elements.isEmpty());+ table.add(noRecords);+ }++}diff --git a/server-core/src/main/java/io/onedev/server/web/page/admin/pluginsettings/ContributedAdministrationSettingPage.java b/server-core/src/main/java/io/onedev/server/web/page/admin/pluginsettings/ContributedAdministrationSettingPage.javaindex acb0582454..034947d7d2 100644--- a/server-core/src/main/java/io/onedev/server/web/page/admin/pluginsettings/ContributedAdministrationSettingPage.java+++ b/server-core/src/main/java/io/onedev/server/web/page/admin/pluginsettings/ContributedAdministrationSettingPage.java@@ -1,11 +1,13 @@package io.onedev.server.web.page.admin.pluginsettings;-import java.io.Serializable;-import java.lang.reflect.InvocationTargetException;--import javax.annotation.Nullable;-import javax.validation.Validator;-+import io.onedev.server.OneDev;+import io.onedev.server.entitymanager.SettingManager;+import io.onedev.server.web.editable.BeanContext;+import io.onedev.server.web.editable.BeanEditor;+import io.onedev.server.web.editable.EditableUtils;+import io.onedev.server.web.page.admin.AdministrationPage;+import io.onedev.server.web.page.layout.AdministrationSettingContribution;+import io.onedev.server.web.page.layout.ContributedAdministrationSetting;import org.apache.wicket.Component;import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;@@ -16,14 +18,10 @@ import org.apache.wicket.markup.html.form.Form;import org.apache.wicket.model.IModel;import org.apache.wicket.request.mapper.parameter.PageParameters;-import io.onedev.server.OneDev;-import io.onedev.server.entitymanager.SettingManager;-import io.onedev.server.web.editable.BeanContext;-import io.onedev.server.web.editable.BeanEditor;-import io.onedev.server.web.editable.EditableUtils;-import io.onedev.server.web.page.admin.AdministrationPage;-import io.onedev.server.web.page.layout.ContributedAdministrationSetting;-import io.onedev.server.web.page.layout.AdministrationSettingContribution;+import javax.annotation.Nullable;+import javax.validation.Validator;+import java.io.Serializable;+import java.lang.reflect.InvocationTargetException;@SuppressWarnings("serial")public class ContributedAdministrationSettingPage extends AdministrationPage {@@ -75,9 +73,9 @@ public class ContributedAdministrationSettingPage extends AdministrationPage {Component editor = get("editor");if (editor instanceof BeanEditor && editor.isVisible())- getSettingManager().saveContributedSetting(settingClass, (ContributedAdministrationSetting) ((BeanEditor)editor).getModelObject());+ getSettingManager().saveContributedSetting((ContributedAdministrationSetting) ((BeanEditor)editor).getModelObject());else- getSettingManager().saveContributedSetting(settingClass, null);+ getSettingManager().removeContributedSetting(settingClass);getSession().success("Setting has been saved");diff --git a/server-ee b/server-eeindex 7393639021..ca51e65adc 160000--- a/server-ee+++ b/server-ee@@ -1 +1 @@-Subproject commit 73936390215fab0ef0388644dfd53f31ee049bf2+Subproject commit ca51e65adca235600bc929ff00944d7c01dc2e51diff --git a/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java b/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.javaindex 5f514a7d1b..8d5a4ab93a 100644--- a/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java+++ b/server-plugin/server-plugin-executor-kubernetes/src/main/java/io/onedev/server/plugin/executor/kubernetes/KubernetesExecutor.java@@ -14,7 +14,6 @@ import io.onedev.commons.utils.command.LineConsumer;import io.onedev.k8shelper.*;import io.onedev.server.OneDev;import io.onedev.server.annotation.Editable;-import io.onedev.server.annotation.Horizontal;import io.onedev.server.annotation.OmitName;import io.onedev.server.annotation.ShowCondition;import io.onedev.server.buildspecmodel.inputspec.SecretInput;@@ -66,7 +65,6 @@ import static org.apache.commons.codec.binary.Base64.encodeBase64String;+ "No any agents are required."+ "<b class='text-danger'>Note:</b> Make sure server url is specified correctly in system "+ "settings as job pods need to access it to download source and artifacts")-@Horizontalpublic class KubernetesExecutor extends JobExecutor implements RegistryLoginAware, Testable<TestData> {private static final long serialVersionUID = 1L;diff --git a/server-plugin/server-plugin-executor-remoteshell/src/main/java/io/onedev/server/plugin/executor/remoteshell/RemoteShellExecutor.java b/server-plugin/server-plugin-executor-remoteshell/src/main/java/io/onedev/server/plugin/executor/remoteshell/RemoteShellExecutor.javaindex ab97196964..5f67e92490 100644--- a/server-plugin/server-plugin-executor-remoteshell/src/main/java/io/onedev/server/plugin/executor/remoteshell/RemoteShellExecutor.java+++ b/server-plugin/server-plugin-executor-remoteshell/src/main/java/io/onedev/server/plugin/executor/remoteshell/RemoteShellExecutor.java@@ -8,7 +8,6 @@ import io.onedev.commons.utils.ExplicitException;import io.onedev.commons.utils.TaskLogger;import io.onedev.server.OneDev;import io.onedev.server.annotation.Editable;-import io.onedev.server.annotation.Horizontal;import io.onedev.server.annotation.Numeric;import io.onedev.server.cluster.ClusterManager;import io.onedev.server.entitymanager.AgentManager;@@ -32,7 +31,6 @@ import static io.onedev.agent.WebsocketUtils.call;+ "This executor runs build jobs with remote machines's shell facility via <a href='/~administration/agents' target='_blank'>agents</a><br>"+ "<b class='text-danger'>WARNING</b>: Jobs running with this executor has same permission "+ "as corresponding agent process. Make sure it can only be used by trusted jobs via job requirement setting")-@Horizontalpublic class RemoteShellExecutor extends ServerShellExecutor {private static final long serialVersionUID = 1L;diff --git a/server-plugin/server-plugin-executor-serverdocker/src/main/java/io/onedev/server/plugin/executor/serverdocker/ServerDockerExecutor.java b/server-plugin/server-plugin-executor-serverdocker/src/main/java/io/onedev/server/plugin/executor/serverdocker/ServerDockerExecutor.javaindex cf8b4fb240..15bb30eaa9 100644--- a/server-plugin/server-plugin-executor-serverdocker/src/main/java/io/onedev/server/plugin/executor/serverdocker/ServerDockerExecutor.java+++ b/server-plugin/server-plugin-executor-serverdocker/src/main/java/io/onedev/server/plugin/executor/serverdocker/ServerDockerExecutor.java@@ -47,7 +47,6 @@ import static java.util.stream.Collectors.toList;@Editable(order=ServerDockerExecutor.ORDER, name="Server Docker Executor",description="This executor runs build jobs as docker containers on OneDev server")@ClassValidating-@Horizontalpublic class ServerDockerExecutor extends JobExecutor implements RegistryLoginAware, Testable<TestData>, Validatable {private static final long serialVersionUID = 1L;diff --git a/server-plugin/server-plugin-executor-servershell/src/main/java/io/onedev/server/plugin/executor/servershell/ServerShellExecutor.java b/server-plugin/server-plugin-executor-servershell/src/main/java/io/onedev/server/plugin/executor/servershell/ServerShellExecutor.javaindex 060630f2ff..1f8a2145d4 100644--- a/server-plugin/server-plugin-executor-servershell/src/main/java/io/onedev/server/plugin/executor/servershell/ServerShellExecutor.java+++ b/server-plugin/server-plugin-executor-servershell/src/main/java/io/onedev/server/plugin/executor/servershell/ServerShellExecutor.java@@ -9,7 +9,10 @@ import io.onedev.commons.utils.TaskLogger;import io.onedev.commons.utils.command.Commandline;import io.onedev.k8shelper.*;import io.onedev.server.OneDev;-import io.onedev.server.annotation.*;+import io.onedev.server.annotation.Code;+import io.onedev.server.annotation.Editable;+import io.onedev.server.annotation.Numeric;+import io.onedev.server.annotation.OmitName;import io.onedev.server.cluster.ClusterManager;import io.onedev.server.cluster.ClusterTask;import io.onedev.server.git.location.GitLocation;@@ -42,7 +45,6 @@ import static io.onedev.k8shelper.KubernetesHelper.*;"<b class='text-danger'>WARNING</b>: Jobs running with this executor has same " +"permission as OneDev server process. Make sure it can only be used by trusted " +"jobs via job requirement setting")-@Horizontalpublic class ServerShellExecutor extends JobExecutor implements Testable<TestData> {private static final long serialVersionUID = 1L;diff --git a/server-product/system/incompatibilities/incompatibilities.md b/server-product/system/incompatibilities/incompatibilities.mdindex bed6cb790c..ef3a91ab6d 100644--- a/server-product/system/incompatibilities/incompatibilities.md+++ b/server-product/system/incompatibilities/incompatibilities.md@@ -1,3 +1,12 @@+# 11.6.10++### RESTful API++1. Format of contributed project settings inside project settings (refer to endpoint to [get](/~help/api/io.onedev.server.rest.resource.ProjectResource/getSetting) and [set](/~help/api/io.onedev.server.rest.resource.ProjectResource/updateSetting)+project settings) has been changed+1. Format of contributed administration settings (refer to endpoint to [get](/~help/api/io.onedev.server.rest.resource.SettingResource/getContributedSettings) and [set](/~help/api/io.onedev.server.rest.resource.SettingResource/setContributedSettings)+ contributed administration settings) has been changed+# 11.6.6Incoming box settings of various mail services removed additional target addresses for simplicity reason.