Skip to content

The Unified and Autonomous Development Platform

Fix issue #222 - Use '@@' instead of '\@' for literal @ in job commands

Robin Shen0dd755578155
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/CacheSpec.java b/server-core/src/main/java/io/onedev/server/buildspec/job/CacheSpec.java
index 56522b4d30..d76fefe3ad 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/CacheSpec.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/CacheSpec.java
@@ -20,11 +20,10 @@ public class CacheSpec implements Serializable {
private String path;
- @Editable(order=100, description="Specify key of the cache. Caches with same key can be reused by different jobs. "
- + "Note: Type @ to insert variable, use \\ to escape normal occurrences of @ or \\")
+ @Editable(order=100, description="Specify key of the cache. Caches with same key can be reused by different jobs")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
- @RegEx(interpolative=true, pattern="[a-zA-Z0-9\\-_\\.]+", message="Can only contain alphanumeric, dash, dot and underscore")
+ @RegEx(pattern="[a-zA-Z0-9\\-_\\.]+", message="Can only contain alphanumeric, dash, dot and underscore")
public String getKey() {
return key;
}
@@ -34,8 +33,7 @@ public class CacheSpec implements Serializable {
}
@Editable(order=200, description="Specify path to cache. Non-absolute path is considered to be relative to job workspace. "
- + "Specify \".\" (without quote) to cache workspace itself. "
- + "Note: Type @ to insert variable, use \\ to escape normal occurrences of @ or \\")
+ + "Specify \".\" (without quote) to cache workspace itself")
@Interpolative(variableSuggester="suggestVariables")
@Path
@NotEmpty
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/EnvVar.java b/server-core/src/main/java/io/onedev/server/buildspec/job/EnvVar.java
index 8b78214369..5a8a52feba 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/EnvVar.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/EnvVar.java
@@ -19,10 +19,9 @@ public class EnvVar implements Serializable {
private String value;
- @Editable(order=100, description="Specify name of the environment variable. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=100, description="Specify name of the environment variable")
@Interpolative(variableSuggester="suggestVariables")
- @VariableName(interpolative = true)
+ @VariableName
@NotEmpty
public String getName() {
return name;
@@ -32,8 +31,7 @@ public class EnvVar implements Serializable {
this.name = name;
}
- @Editable(order=200, description="Specify value of the environment variable. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=200, description="Specify value of the environment variable")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getValue() {
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/Job.java b/server-core/src/main/java/io/onedev/server/buildspec/job/Job.java
index e05cf078a5..37be0a0e8e 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/Job.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/Job.java
@@ -134,8 +134,7 @@ public class Job implements Serializable, Validatable {
this.name = name;
}
- @Editable(order=110, description="Specify docker image of the job. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=110, description="Specify docker image of the job")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getImage() {
@@ -174,8 +173,7 @@ public class Job implements Serializable, Validatable {
@Editable(order=120, name="Commands", description="Specify content of Linux shell script or Windows command batch to execute in above image. "
+ "It will be executed under <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>, which may contain files of your repository and "
- + "dependency artifacts based on your configuration below. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ + "dependency artifacts based on your configuration below")
@Interpolative
@Code(language = Code.SHELL, variableProvider="getVariables")
@Size(min=1, message="may not be empty")
@@ -292,10 +290,9 @@ public class Job implements Serializable, Validatable {
}
@Editable(order=9115, group="Artifacts & Reports", description="Optionally specify files to publish as job artifacts. "
- + "Artifact files are relative to <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>, and may use * or ? for pattern match. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ + "Artifact files are relative to <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>, and may use * or ? for pattern match")
@Interpolative(variableSuggester="suggestVariables")
- @Patterns(interpolative = true, path=true)
+ @Patterns(path=true)
@NameOfEmptyValue("No artifacts")
public String getArtifacts() {
return artifacts;
@@ -349,8 +346,7 @@ public class Job implements Serializable, Validatable {
}
@Editable(order=9200, name="CPU Requirement", group="Resource Requirements", description="Specify CPU requirement of the job. "
- + "Refer to <a href='https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu' target='_blank'>kubernetes documentation</a> for details. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ + "Refer to <a href='https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu' target='_blank'>kubernetes documentation</a> for details")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getCpuRequirement() {
@@ -362,8 +358,7 @@ public class Job implements Serializable, Validatable {
}
@Editable(order=9300, group="Resource Requirements", description="Specify memory requirement of the job. "
- + "Refer to <a href='https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-memory' target='_blank'>kubernetes documentation</a> for details. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ + "Refer to <a href='https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-memory' target='_blank'>kubernetes documentation</a> for details")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getMemoryRequirement() {
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/JobDependency.java b/server-core/src/main/java/io/onedev/server/buildspec/job/JobDependency.java
index a3f1047574..cca02f8967 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/JobDependency.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/JobDependency.java
@@ -69,10 +69,9 @@ public class JobDependency implements Serializable {
}
@Editable(order=300, name="Artifacts to Retrieve", description="Optionally specify artifacts to retrieve "
- + "from the dependency into <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>. Leave empty to do not retrieve any artifacts. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ + "from the dependency into <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>. Leave empty to do not retrieve any artifacts")
@Interpolative(variableSuggester="suggestVariables")
- @Patterns(interpolative = true, path=true)
+ @Patterns(path=true)
@NameOfEmptyValue("Do not retrieve")
public String getArtifacts() {
return artifacts;
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/JobReport.java b/server-core/src/main/java/io/onedev/server/buildspec/job/JobReport.java
index 9b991b827c..0166b2a3bc 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/JobReport.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/JobReport.java
@@ -37,10 +37,9 @@ public abstract class JobReport implements Serializable {
this.reportName = reportName;
}
- @Editable(order=100, description="Specify files relative to OneDev workspace. Use * or ? for pattern match. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=100, description="Specify files relative to OneDev workspace. Use * or ? for pattern match")
@Interpolative(variableSuggester="suggestVariables")
- @Patterns(interpolative = true, path=true)
+ @Patterns(path=true)
@NotEmpty
public String getFilePatterns() {
return filePatterns;
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/JobService.java b/server-core/src/main/java/io/onedev/server/buildspec/job/JobService.java
index ffbca0e829..60ac72f46b 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/JobService.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/JobService.java
@@ -30,10 +30,9 @@ public class JobService implements Serializable {
private String memoryRequirement = "128m";
- @Editable(order=100, description="Specify name of the service, which will be used as host name to access "
- + "the service. <b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=100, description="Specify name of the service, which will be used as host name to access the service")
@Interpolative(variableSuggester="suggestVariables")
- @DnsName(interpolative = true)
+ @DnsName
@NotEmpty
public String getName() {
return name;
@@ -43,8 +42,7 @@ public class JobService implements Serializable {
this.name = name;
}
- @Editable(order=200, description="Specify docker image of the service. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=200, description="Specify docker image of the service")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getImage() {
@@ -55,8 +53,7 @@ public class JobService implements Serializable {
this.image = image;
}
- @Editable(order=220, description="Optionally specify arguments to run above image. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=220, description="Optionally specify arguments to run above image")
@Interpolative(variableSuggester="suggestVariables")
public String getArguments() {
return arguments;
@@ -78,8 +75,7 @@ public class JobService implements Serializable {
@Editable(order=400, description="Specify command to check readiness of the service. This command will "
+ "be interpretated by cmd.exe on Windows images, and by shell on Linux images. It will be "
- + "executed repeatedly until a zero code is returned to indicate service ready. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ + "executed repeatedly until a zero code is returned to indicate service ready")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getReadinessCheckCommand() {
@@ -91,8 +87,7 @@ public class JobService implements Serializable {
}
@Editable(order=10000, name="CPU Requirement", group="More Settings", description="Specify CPU requirement of the job. "
- + "Refer to <a href='https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu' target='_blank'>kubernetes documentation</a> for details. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ + "Refer to <a href='https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-cpu' target='_blank'>kubernetes documentation</a> for details")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getCpuRequirement() {
@@ -104,8 +99,7 @@ public class JobService implements Serializable {
}
@Editable(order=10100, group="More Settings", description="Specify memory requirement of the job. "
- + "Refer to <a href='https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-memory' target='_blank'>kubernetes documentation</a> for details. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ + "Refer to <a href='https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-memory' target='_blank'>kubernetes documentation</a> for details")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getMemoryRequirement() {
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/ProjectDependency.java b/server-core/src/main/java/io/onedev/server/buildspec/job/ProjectDependency.java
index 995af00113..1f1023bdf8 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/ProjectDependency.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/ProjectDependency.java
@@ -19,7 +19,7 @@ import io.onedev.server.model.Project;
import io.onedev.server.security.SecurityUtils;
import io.onedev.server.security.permission.AccessProject;
import io.onedev.server.util.EditContext;
-import io.onedev.server.util.interpolative.Segment;
+import io.onedev.server.util.interpolative.Interpolative.Segment;
import io.onedev.server.web.behavior.inputassist.InputAssistBehavior;
import io.onedev.server.web.editable.annotation.ChoiceProvider;
import io.onedev.server.web.editable.annotation.Editable;
@@ -69,8 +69,7 @@ public class ProjectDependency implements Serializable {
return choices;
}
- @Editable(order=300, name="Build", description="Specify build to retrieve artifacts from. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=300, name="Build", description="Specify build to retrieve artifacts from")
@Interpolative(variableSuggester="suggestVariables", literalSuggester="suggestBuilds")
@NotEmpty
public String getBuildNumber() {
@@ -101,10 +100,9 @@ public class ProjectDependency implements Serializable {
return new ArrayList<>();
}
- @Editable(order=400, name="Artifacts to Retrieve", description="Specify artifacts to retrieve into <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=400, name="Artifacts to Retrieve", description="Specify artifacts to retrieve into <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>")
@Interpolative(variableSuggester="suggestVariables")
- @Patterns(suggester="suggestArtifacts", interpolative=true, path=true)
+ @Patterns(suggester="suggestArtifacts", path=true)
@NotEmpty
public String getArtifacts() {
return artifacts;
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/action/CloseMilestoneAction.java b/server-core/src/main/java/io/onedev/server/buildspec/job/action/CloseMilestoneAction.java
index a00e237131..a6d04492fc 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/action/CloseMilestoneAction.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/action/CloseMilestoneAction.java
@@ -23,8 +23,7 @@ public class CloseMilestoneAction extends PostBuildAction {
private String milestoneName;
- @Editable(order=1000, description="Specify name of the milestone. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=1000, description="Specify name of the milestone")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getMilestoneName() {
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateIssueAction.java b/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateIssueAction.java
index 851f34532e..91f9546392 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateIssueAction.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateIssueAction.java
@@ -40,8 +40,7 @@ public class CreateIssueAction extends PostBuildAction {
private List<FieldSupply> issueFields = new ArrayList<>();
- @Editable(order=1000, name="Title", group="Issue Detail", description="Specify title of the issue. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=1000, name="Title", group="Issue Detail", description="Specify title of the issue")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getIssueTitle() {
@@ -52,8 +51,7 @@ public class CreateIssueAction extends PostBuildAction {
this.issueTitle = issueTitle;
}
- @Editable(order=1050, name="Description", group="Issue Detail", description="Optionally specify description of the issue. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=1050, name="Description", group="Issue Detail", description="Optionally specify description of the issue")
@Multiline
@Interpolative(variableSuggester="suggestVariables")
public String getIssueDescription() {
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateTagAction.java b/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateTagAction.java
index 4b8b2a9f63..d186c6de3b 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateTagAction.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/job/action/CreateTagAction.java
@@ -27,8 +27,7 @@ public class CreateTagAction extends PostBuildAction {
private String tagMessage;
- @Editable(order=1000, description="Specify name of the tag. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=1000, description="Specify name of the tag")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getTagName() {
@@ -39,8 +38,7 @@ public class CreateTagAction extends PostBuildAction {
this.tagName = tagName;
}
- @Editable(order=1050, description="Optionally specify message of the tag. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=1050, description="Optionally specify message of the tag")
@Multiline
@Interpolative(variableSuggester="suggestVariables")
public String getTagMessage() {
diff --git a/server-core/src/main/java/io/onedev/server/model/Build.java b/server-core/src/main/java/io/onedev/server/model/Build.java
index 81b65ae53c..0cc18c2ad5 100644
--- a/server-core/src/main/java/io/onedev/server/model/Build.java
+++ b/server-core/src/main/java/io/onedev/server/model/Build.java
@@ -908,7 +908,7 @@ public class Build extends AbstractEntity implements Referenceable {
public String interpolate(@Nullable String interpolativeString) {
if (interpolativeString != null)
- return StringUtils.unescape(Interpolative.parse(interpolativeString).interpolateWith(new VariableInterpolator(this)));
+ return Interpolative.parse(interpolativeString).interpolateWith(new VariableInterpolator(this));
else
return null;
}
diff --git a/server-core/src/main/java/io/onedev/server/util/interpolative/Interpolative.g4 b/server-core/src/main/java/io/onedev/server/util/interpolative/Interpolative.g4
index 83a9ac2386..e823e578ee 100644
--- a/server-core/src/main/java/io/onedev/server/util/interpolative/Interpolative.g4
+++ b/server-core/src/main/java/io/onedev/server/util/interpolative/Interpolative.g4
@@ -4,6 +4,7 @@ interpolative: segment* EOF;
segment: Literal|Variable;
-Variable: '@' CHAR+? '@';
-Literal: CHAR+;
-CHAR: ('\\'.|~[@\\]);
+Variable: '@' VariableChar+? '@';
+Literal: LiteralChar+;
+LiteralChar: '@@'|~[@];
+VariableChar: ~[@];
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/util/interpolative/Interpolative.java b/server-core/src/main/java/io/onedev/server/util/interpolative/Interpolative.java
index 50093cec44..b538cc579c 100644
--- a/server-core/src/main/java/io/onedev/server/util/interpolative/Interpolative.java
+++ b/server-core/src/main/java/io/onedev/server/util/interpolative/Interpolative.java
@@ -17,8 +17,9 @@ import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import io.onedev.commons.codeassist.FenceAware;
+import io.onedev.commons.utils.ExplicitException;
+import io.onedev.server.util.interpolative.Interpolative.Segment.Type;
import io.onedev.server.util.interpolative.InterpolativeParser.SegmentContext;
-import io.onedev.server.util.interpolative.Segment.Type;
public class Interpolative implements Serializable {
@@ -39,7 +40,8 @@ public class Interpolative implements Serializable {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
int charPositionInLine, String msg, RecognitionException e) {
- throw new RuntimeException("Malformed interpolative: " + interpolativeString);
+ throw new ExplicitException("Last appearance of @ is a surprise to me. Either use @...@ to reference "
+ + "a variable, or use @@ for literal @: " + interpolativeString);
}
});
@@ -51,11 +53,11 @@ public class Interpolative implements Serializable {
List<Segment> segments = new ArrayList<>();
for (SegmentContext segment: parser.interpolative().segment()) {
if (segment.Literal() != null)
- segments.add(new Segment(Type.LITERAL, segment.Literal().getText()));
+ segments.add(new Segment(Type.LITERAL, segment.Literal().getText().replace("@@", "@")));
else
segments.add(new Segment(Type.VARIABLE, FenceAware.unfence(segment.Variable().getText())));
}
- return new Interpolative(segments);
+ return new Interpolative(segments);
}
public List<Segment> getSegments(@Nullable Type type) {
@@ -76,4 +78,29 @@ public class Interpolative implements Serializable {
return builder.toString();
}
+ public static class Segment implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public enum Type {LITERAL, VARIABLE};
+
+ private final Type type;
+
+ private final String content;
+
+ public Segment(Type type, String content) {
+ this.type = type;
+ this.content = content;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ }
+
}
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/util/interpolative/Segment.java b/server-core/src/main/java/io/onedev/server/util/interpolative/Segment.java
deleted file mode 100644
index 8c15140f11..0000000000
--- a/server-core/src/main/java/io/onedev/server/util/interpolative/Segment.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package io.onedev.server.util.interpolative;
-
-import java.io.Serializable;
-
-public class Segment implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- public enum Type {LITERAL, VARIABLE};
-
- private final Type type;
-
- private final String content;
-
- public Segment(Type type, String content) {
- this.type = type;
- this.content = content;
- }
-
- public Type getType() {
- return type;
- }
-
- public String getContent() {
- return content;
- }
-
-}
diff --git a/server-core/src/main/java/io/onedev/server/util/patternset/InterpolativePatternSet.g4 b/server-core/src/main/java/io/onedev/server/util/patternset/InterpolativePatternSet.g4
index 62de679030..2d31c7f6db 100644
--- a/server-core/src/main/java/io/onedev/server/util/patternset/InterpolativePatternSet.g4
+++ b/server-core/src/main/java/io/onedev/server/util/patternset/InterpolativePatternSet.g4
@@ -5,9 +5,9 @@ segment: literal|Variable;
literal: WS* pattern (WS+ pattern)* WS*;
pattern: Excluded? (Quoted|NQuoted);
-Variable: '@' ('\\'.|~[\\@])+? '@';
-Quoted: '"' ('\\'.|~[\\@"])+? '"';
-NQuoted: (~[-"@ ]|'\\'.)(~["@ ]|'\\'.)*;
+Variable: '@' (~[@])+? '@';
+Quoted: '"' ('@@'|'\\'~[@]|~[\\"@])+? '"';
+NQuoted: ('@@'|~[-\\"@ ]|'\\'~[@])('@@'|~["\\@ ]|'\\'~[@])*;
Excluded: '-';
WS: ' ';
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/CommitHashValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/CommitHashValidator.java
index dcfd25d913..b60e992ad4 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/CommitHashValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/CommitHashValidator.java
@@ -5,25 +5,20 @@ import javax.validation.ConstraintValidatorContext;
import org.eclipse.jgit.lib.ObjectId;
-import io.onedev.server.util.interpolative.Interpolative;
-import io.onedev.server.util.interpolative.Segment;
import io.onedev.server.util.validation.annotation.CommitHash;
public class CommitHashValidator implements ConstraintValidator<CommitHash, String> {
- private boolean interpolative;
-
private String message;
@Override
public void initialize(CommitHash constaintAnnotation) {
- interpolative = constaintAnnotation.interpolative();
message = constaintAnnotation.message();
}
@Override
public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
- if (value == null || interpolative && !Interpolated.get() && !Interpolative.parse(value).getSegments(Segment.Type.VARIABLE).isEmpty())
+ if (value == null)
return true;
if (!ObjectId.isId(value)) {
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/DirectoryValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/DirectoryValidator.java
index 0e24dde817..bd46a01939 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/DirectoryValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/DirectoryValidator.java
@@ -1,15 +1,12 @@
package io.onedev.server.util.validation;
import java.io.File;
-import java.util.function.Function;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import io.onedev.commons.launcher.bootstrap.Bootstrap;
import io.onedev.commons.utils.FileUtils;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.Directory;
public class DirectoryValidator implements ConstraintValidator<Directory, String> {
@@ -26,19 +23,6 @@ public class DirectoryValidator implements ConstraintValidator<Directory, String
if (value == null)
return true;
- if (annotation.interpolative() && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
-
try {
File dir = new File(value);
if (annotation.absolute()) {
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/DnsNameValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/DnsNameValidator.java
index 866d1da9db..2d304d485b 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/DnsNameValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/DnsNameValidator.java
@@ -1,21 +1,16 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.DnsName;
public class DnsNameValidator implements ConstraintValidator<DnsName, String> {
private static final Pattern PATTERN = Pattern.compile("[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?");
- private boolean interpolative;
-
private String message;
@Override
@@ -28,19 +23,6 @@ public class DnsNameValidator implements ConstraintValidator<DnsName, String> {
if (value == null)
return true;
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
-
if (!PATTERN.matcher(value).matches()) {
String message = this.message;
if (message.length() == 0) {
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/GroupNameValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/GroupNameValidator.java
index 4bd9849a06..a4bde4b3bd 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/GroupNameValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/GroupNameValidator.java
@@ -1,26 +1,20 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.GroupName;
public class GroupNameValidator implements ConstraintValidator<GroupName, String> {
public static final Pattern PATTERN = Pattern.compile("\\w([\\w-\\.]*\\w)?");
- private boolean interpolative;
-
private String message;
@Override
public void initialize(GroupName constaintAnnotation) {
- interpolative = constaintAnnotation.interpolative();
message = constaintAnnotation.message();
}
@@ -29,19 +23,6 @@ public class GroupNameValidator implements ConstraintValidator<GroupName, String
if (value == null)
return true;
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
-
if (!PATTERN.matcher(value).matches()) {
constraintContext.disableDefaultConstraintViolation();
String message = this.message;
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/Interpolated.java b/server-core/src/main/java/io/onedev/server/util/validation/Interpolated.java
deleted file mode 100644
index 973b197c32..0000000000
--- a/server-core/src/main/java/io/onedev/server/util/validation/Interpolated.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package io.onedev.server.util.validation;
-
-import java.util.Stack;
-
-public class Interpolated {
-
- private static ThreadLocal<Stack<Boolean>> stack = new ThreadLocal<Stack<Boolean>>() {
-
- @Override
- protected Stack<Boolean> initialValue() {
- return new Stack<Boolean>();
- }
-
- };
-
- public static void push(boolean interpolated) {
- stack.get().push(interpolated);
- }
-
- public static void pop() {
- stack.get().pop();
- }
-
- public static boolean get() {
- if (!stack.get().isEmpty())
- return stack.get().peek();
- else
- return false;
- }
-
-}
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/InterpolativeValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/InterpolativeValidator.java
index a6be948e2b..0d994b80ed 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/InterpolativeValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/InterpolativeValidator.java
@@ -24,26 +24,27 @@ public class InterpolativeValidator implements ConstraintValidator<Interpolative
if (value == null)
return true;
- if (!Interpolated.get()) {
- List<String> values = new ArrayList<>();
- if (value instanceof Collection)
- values.addAll((Collection<String>)value);
- else
- values.add((String) value);
-
- for (String each: values) {
- try {
- io.onedev.server.util.interpolative.Interpolative.parse(each);
- } catch (Exception e) {
- constraintContext.disableDefaultConstraintViolation();
- String message = this.message;
- if (message.length() == 0)
- message = "Malformed interpolative: please make sure '@' and '\\' is escaped appropriately";
- constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();
- return false;
+ List<String> values = new ArrayList<>();
+ if (value instanceof Collection)
+ values.addAll((Collection<String>)value);
+ else
+ values.add((String) value);
+
+ for (String each: values) {
+ try {
+ io.onedev.server.util.interpolative.Interpolative.parse(each);
+ } catch (Exception e) {
+ constraintContext.disableDefaultConstraintViolation();
+ String message = this.message;
+ if (message.length() == 0) {
+ message = "Last appearance of @ is a surprise to me. Either use @...@ to reference a variable, "
+ + "or use @@ for literal @";
}
+ constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();
+ return false;
}
- }
+ }
return true;
}
+
}
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/NumericValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/NumericValidator.java
index 8ee2db26ad..cc9cf69cc6 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/NumericValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/NumericValidator.java
@@ -1,18 +1,12 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
-
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.web.editable.annotation.Numeric;
public class NumericValidator implements ConstraintValidator<Numeric, String> {
- private boolean interpolative;
-
private String message;
@Override
@@ -24,20 +18,6 @@ public class NumericValidator implements ConstraintValidator<Numeric, String> {
public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
if (value == null)
return true;
-
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "1";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
-
try {
Long.parseLong(value);
} catch (NumberFormatException e) {
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/PathSegmentValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/PathSegmentValidator.java
index 863650079c..4734415378 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/PathSegmentValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/PathSegmentValidator.java
@@ -1,24 +1,18 @@
package io.onedev.server.util.validation;
import java.nio.file.Paths;
-import java.util.function.Function;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.PathSegment;
public class PathSegmentValidator implements ConstraintValidator<PathSegment, String> {
- private boolean interpolative;
-
private String message;
@Override
public void initialize(PathSegment constaintAnnotation) {
- interpolative = constaintAnnotation.interpolative();
message = constaintAnnotation.message();
}
@@ -27,19 +21,6 @@ public class PathSegmentValidator implements ConstraintValidator<PathSegment, St
if (value == null)
return true;
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
-
boolean valid = true;
String message = this.message;
if (value.contains("/") || value.contains("\\")) {
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/PathValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/PathValidator.java
index c7c4143086..0a3203f66f 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/PathValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/PathValidator.java
@@ -1,24 +1,18 @@
package io.onedev.server.util.validation;
import java.nio.file.Paths;
-import java.util.function.Function;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.Path;
public class PathValidator implements ConstraintValidator<Path, String> {
- private boolean interpolative;
-
private String message;
@Override
public void initialize(Path constaintAnnotation) {
- interpolative = constaintAnnotation.interpolative();
message = constaintAnnotation.message();
}
@@ -26,19 +20,6 @@ public class PathValidator implements ConstraintValidator<Path, String> {
public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
if (value == null)
return true;
-
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
try {
Paths.get(value);
return true;
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/PatternsValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/PatternsValidator.java
index 859f37f64a..d059a36b69 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/PatternsValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/PatternsValidator.java
@@ -1,24 +1,18 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
-
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.patternset.PatternSet;
import io.onedev.server.web.editable.annotation.Patterns;
public class PatternsValidator implements ConstraintValidator<Patterns, String> {
- private boolean interpolative;
-
private String message;
@Override
public void initialize(Patterns constaintAnnotation) {
- interpolative = constaintAnnotation.interpolative();
message = constaintAnnotation.message();
}
@@ -26,18 +20,6 @@ public class PatternsValidator implements ConstraintValidator<Patterns, String>
public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
if (value == null)
return true;
- if (interpolative && !Interpolated.get()) try {
- value = Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- });
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
try {
PatternSet.parse(value);
return true;
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/ProjectNameValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/ProjectNameValidator.java
index 021c2f6b40..e36b7d291c 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/ProjectNameValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/ProjectNameValidator.java
@@ -1,27 +1,21 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.ProjectName;
public class ProjectNameValidator implements ConstraintValidator<ProjectName, String> {
public static final Pattern PATTERN = Pattern.compile("\\w([\\w-\\.]*\\w)?");
- private boolean interpolative;
-
private String message;
@Override
public void initialize(ProjectName constaintAnnotation) {
message = constaintAnnotation.message();
- interpolative = constaintAnnotation.interpolative();
}
@Override
@@ -29,19 +23,6 @@ public class ProjectNameValidator implements ConstraintValidator<ProjectName, St
if (value == null)
return true;
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
-
if (!PATTERN.matcher(value).matches()) {
constraintContext.disableDefaultConstraintViolation();
String message = this.message;
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/RegExValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/RegExValidator.java
index a6328a3625..24963b55be 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/RegExValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/RegExValidator.java
@@ -1,26 +1,20 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.RegEx;
public class RegExValidator implements ConstraintValidator<RegEx, String> {
- private boolean interpolative;
-
private Pattern pattern;
private String message;
@Override
public void initialize(RegEx constaintAnnotation) {
- interpolative = constaintAnnotation.interpolative();
pattern = Pattern.compile(constaintAnnotation.pattern());
message = constaintAnnotation.message();
}
@@ -29,19 +23,6 @@ public class RegExValidator implements ConstraintValidator<RegEx, String> {
public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
if (value == null)
return true;
-
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
if (pattern.matcher(value).matches()) {
return true;
} else {
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/SecretNameValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/SecretNameValidator.java
index f39b7279af..57f86af841 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/SecretNameValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/SecretNameValidator.java
@@ -1,26 +1,20 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.SecretName;
public class SecretNameValidator implements ConstraintValidator<SecretName, String> {
public static final Pattern PATTERN = Pattern.compile("\\w([\\w-\\.]*\\w)?");
- private boolean interpolative;
-
private String message;
@Override
public void initialize(SecretName constaintAnnotation) {
- interpolative = constaintAnnotation.interpolative();
message = constaintAnnotation.message();
}
@@ -29,19 +23,6 @@ public class SecretNameValidator implements ConstraintValidator<SecretName, Stri
if (value == null)
return true;
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
-
if (!PATTERN.matcher(value).matches()) {
String message = this.message;
if (message.length() == 0) {
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/UrlSegmentValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/UrlSegmentValidator.java
index 60feec0d99..4570693d85 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/UrlSegmentValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/UrlSegmentValidator.java
@@ -1,27 +1,21 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.UrlSegment;
public class UrlSegmentValidator implements ConstraintValidator<UrlSegment, String> {
public static final Pattern PATTERN = Pattern.compile("\\w([\\w-\\.]*\\w)?");
- private boolean interpolative;
-
private String message;
@Override
public void initialize(UrlSegment constaintAnnotation) {
message = constaintAnnotation.message();
- interpolative = constaintAnnotation.interpolative();
}
@Override
@@ -29,19 +23,6 @@ public class UrlSegmentValidator implements ConstraintValidator<UrlSegment, Stri
if (value == null)
return true;
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
-
if (!PATTERN.matcher(value).matches()) {
constraintContext.disableDefaultConstraintViolation();
String message = this.message;
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/UserNameValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/UserNameValidator.java
index 95ad38eefd..d250012e8b 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/UserNameValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/UserNameValidator.java
@@ -1,27 +1,21 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
import io.onedev.server.OneDev;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.UserName;
public class UserNameValidator implements ConstraintValidator<UserName, String> {
public static final Pattern PATTERN = Pattern.compile("\\w([\\w-\\.]*\\w)?");
- private boolean interpolative;
-
private String message;
@Override
public void initialize(UserName constaintAnnotation) {
- interpolative = constaintAnnotation.interpolative();
message = constaintAnnotation.message();
}
@@ -30,19 +24,6 @@ public class UserNameValidator implements ConstraintValidator<UserName, String>
if (value == null)
return true;
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
-
if (!PATTERN.matcher(value).matches()) {
constraintContext.disableDefaultConstraintViolation();
String message = this.message;
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/VariableNameValidator.java b/server-core/src/main/java/io/onedev/server/util/validation/VariableNameValidator.java
index 0cf3849bfc..f08a273299 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/VariableNameValidator.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/VariableNameValidator.java
@@ -1,24 +1,17 @@
package io.onedev.server.util.validation;
-import java.util.function.Function;
-
import javax.lang.model.SourceVersion;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-import io.onedev.commons.utils.StringUtils;
-import io.onedev.server.util.interpolative.Interpolative;
import io.onedev.server.util.validation.annotation.VariableName;
public class VariableNameValidator implements ConstraintValidator<VariableName, String> {
- private boolean interpolative;
-
private String message;
@Override
public void initialize(VariableName constaintAnnotation) {
- interpolative = constaintAnnotation.interpolative();
message = constaintAnnotation.message();
}
@@ -26,19 +19,6 @@ public class VariableNameValidator implements ConstraintValidator<VariableName,
public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
if (value == null)
return true;
-
- if (interpolative && !Interpolated.get()) try {
- value = StringUtils.unescape(Interpolative.parse(value).interpolateWith(new Function<String, String>() {
-
- @Override
- public String apply(String t) {
- return "a";
- }
-
- }));
- } catch (Exception e) {
- return true; // will be handled by interpolative validator
- }
if (!SourceVersion.isIdentifier(value) || value.contains("$")) {
constraintContext.disableDefaultConstraintViolation();
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/CommitHash.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/CommitHash.java
index 15fe5d7d19..77e91f1043 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/CommitHash.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/CommitHash.java
@@ -14,8 +14,6 @@ import io.onedev.server.util.validation.CommitHashValidator;
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy=CommitHashValidator.class)
public @interface CommitHash {
-
- boolean interpolative() default false;
String message() default "Not a valid commit hash";
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/Directory.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/Directory.java
index d7b03d3d33..4a11469306 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/Directory.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/Directory.java
@@ -18,8 +18,6 @@ import io.onedev.server.util.validation.DirectoryValidator;
@Constraint(validatedBy=DirectoryValidator.class)
public @interface Directory {
- boolean interpolative() default false;
-
boolean writeable();
boolean outsideOfInstallDir();
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/DnsName.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/DnsName.java
index 1fd542236e..3424ac8443 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/DnsName.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/DnsName.java
@@ -15,8 +15,6 @@ import io.onedev.server.util.validation.DnsNameValidator;
@Constraint(validatedBy=DnsNameValidator.class)
public @interface DnsName {
- boolean interpolative() default false;
-
String message() default "";
Class<?>[] groups() default {};
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/GroupName.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/GroupName.java
index 34ea40a876..1715bb18a9 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/GroupName.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/GroupName.java
@@ -15,8 +15,6 @@ import io.onedev.server.util.validation.GroupNameValidator;
@Constraint(validatedBy=GroupNameValidator.class)
public @interface GroupName {
- boolean interpolative() default false;
-
String message() default "";
Class<?>[] groups() default {};
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/Path.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/Path.java
index f395d93e99..e2ddf07858 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/Path.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/Path.java
@@ -18,8 +18,6 @@ import io.onedev.server.util.validation.PathValidator;
@Constraint(validatedBy=PathValidator.class)
public @interface Path {
- boolean interpolative() default false;
-
String message() default "Invalid path";
Class<?>[] groups() default {};
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/PathSegment.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/PathSegment.java
index ea7f10b82a..88bb94305d 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/PathSegment.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/PathSegment.java
@@ -18,8 +18,6 @@ import io.onedev.server.util.validation.PathSegmentValidator;
@Constraint(validatedBy=PathSegmentValidator.class)
public @interface PathSegment {
- boolean interpolative() default false;
-
String message() default "";
Class<?>[] groups() default {};
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/ProjectName.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/ProjectName.java
index a6fe51c8c1..c4135f7217 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/ProjectName.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/ProjectName.java
@@ -15,8 +15,6 @@ import io.onedev.server.util.validation.ProjectNameValidator;
@Constraint(validatedBy=ProjectNameValidator.class)
public @interface ProjectName {
- boolean interpolative() default false;
-
String message() default "";
Class<?>[] groups() default {};
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/RegEx.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/RegEx.java
index 1300225437..a309e283b3 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/RegEx.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/RegEx.java
@@ -15,8 +15,6 @@ import io.onedev.server.util.validation.RegExValidator;
@Constraint(validatedBy=RegExValidator.class)
public @interface RegEx {
- boolean interpolative() default false;
-
String pattern();
String message() default "Not matching specified regular expression";
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/SecretName.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/SecretName.java
index 2b5b133bff..80305f6553 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/SecretName.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/SecretName.java
@@ -15,8 +15,6 @@ import io.onedev.server.util.validation.SecretNameValidator;
@Constraint(validatedBy=SecretNameValidator.class)
public @interface SecretName {
- boolean interpolative() default false;
-
String message() default "";
Class<?>[] groups() default {};
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/UrlSegment.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/UrlSegment.java
index ab2f710d68..52e7418604 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/UrlSegment.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/UrlSegment.java
@@ -15,8 +15,6 @@ import io.onedev.server.util.validation.UrlSegmentValidator;
@Constraint(validatedBy=UrlSegmentValidator.class)
public @interface UrlSegment {
- boolean interpolative() default false;
-
String message() default "";
Class<?>[] groups() default {};
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/UserName.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/UserName.java
index 399fd9cde3..87062dec85 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/UserName.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/UserName.java
@@ -15,8 +15,6 @@ import io.onedev.server.util.validation.UserNameValidator;
@Constraint(validatedBy=UserNameValidator.class)
public @interface UserName {
- boolean interpolative() default false;
-
String message() default "";
Class<?>[] groups() default {};
diff --git a/server-core/src/main/java/io/onedev/server/util/validation/annotation/VariableName.java b/server-core/src/main/java/io/onedev/server/util/validation/annotation/VariableName.java
index 088425940f..e2ff81c5bf 100644
--- a/server-core/src/main/java/io/onedev/server/util/validation/annotation/VariableName.java
+++ b/server-core/src/main/java/io/onedev/server/util/validation/annotation/VariableName.java
@@ -15,8 +15,6 @@ import io.onedev.server.util.validation.VariableNameValidator;
@Constraint(validatedBy=VariableNameValidator.class)
public @interface VariableName {
- boolean interpolative() default false;
-
String message() default "name should start with letter and can only consist of "
+ "alphanumeric and underscore characters";
diff --git a/server-core/src/main/java/io/onedev/server/web/behavior/InterpolativePatternSetAssistBehavior.java b/server-core/src/main/java/io/onedev/server/web/behavior/InterpolativePatternSetAssistBehavior.java
index df4f8ef576..79c1fdfb64 100644
--- a/server-core/src/main/java/io/onedev/server/web/behavior/InterpolativePatternSetAssistBehavior.java
+++ b/server-core/src/main/java/io/onedev/server/web/behavior/InterpolativePatternSetAssistBehavior.java
@@ -1,5 +1,6 @@
package io.onedev.server.web.behavior;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -55,9 +56,9 @@ public abstract class InterpolativePatternSetAssistBehavior extends ANTLRAssistB
Set<String> matches = new HashSet<>();
for (Token token: terminalExpect.getRoot().getState().getMatchedTokens()) {
if (token.getType() == InterpolativePatternSetLexer.Quoted)
- matches.add(StringUtils.unescape(FenceAware.unfence(token.getText())));
+ matches.add(StringUtils.unescape(FenceAware.unfence(token.getText())).replace("@@", "@"));
else
- matches.add(StringUtils.unescape(token.getText()));
+ matches.add(StringUtils.unescape(token.getText()).replace("@@", "@"));
}
if (spec.getRuleName().equals("NQuoted")) {
List<InputSuggestion> suggestions = suggestPatterns(unmatched);
@@ -67,7 +68,7 @@ public abstract class InterpolativePatternSetAssistBehavior extends ANTLRAssistB
.map(it->{
if (it.getContent().contains(" ") || it.getContent().startsWith("-")) {
InputSuggestion suggestion = it.escape("\"@");
- suggestion = new InputSuggestion("\"" + suggestion.getContent() + "\"",
+ suggestion = new InputSuggestion("\"" + suggestion.getContent().replace("\\@", "@@") + "\"",
suggestion.getCaret()!=-1? suggestion.getCaret()+1: -1,
suggestion.getDescription(),
new LinearRange(suggestion.getMatch().getFrom()+1, suggestion.getMatch().getTo()+1));
@@ -82,7 +83,7 @@ public abstract class InterpolativePatternSetAssistBehavior extends ANTLRAssistB
* provide this suggestion only when we typed quote as otherwise we will have duplicated suggestions
* (one for nquoted, and one for quoted)
*/
- return new FenceAware(codeAssist.getGrammar(), '"', '"', "@") {
+ List<InputSuggestion> suggestions = new FenceAware(codeAssist.getGrammar(), '"', '"', "@") {
@Override
protected List<InputSuggestion> match(String matchWith) {
@@ -102,6 +103,13 @@ public abstract class InterpolativePatternSetAssistBehavior extends ANTLRAssistB
}
}.suggest(terminalExpect);
+
+ List<InputSuggestion> atEscapedSuggestions = new ArrayList<>();
+ for (InputSuggestion suggestion: suggestions) {
+ atEscapedSuggestions.add(new InputSuggestion(suggestion.getContent().replace("\\@", "@@"),
+ suggestion.getCaret(), suggestion.getDescription(), suggestion.getMatch()));
+ }
+ return atEscapedSuggestions;
}
}
}
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/PropertyDescriptor.java b/server-core/src/main/java/io/onedev/server/web/editable/PropertyDescriptor.java
index 6b66b42fc2..2e6cc19232 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/PropertyDescriptor.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/PropertyDescriptor.java
@@ -22,6 +22,7 @@ import io.onedev.server.OneDev;
import io.onedev.server.util.BeanUtils;
import io.onedev.server.util.ComponentContext;
import io.onedev.server.util.ReflectionUtils;
+import io.onedev.server.web.editable.annotation.Interpolative;
import io.onedev.server.web.editable.annotation.NameOfEmptyValue;
import io.onedev.server.web.editable.annotation.ShowCondition;
@@ -189,10 +190,16 @@ public class PropertyDescriptor implements Serializable {
public String getDescription() {
String description = EditableUtils.getDescription(getPropertyGetter());
- if (description != null)
+ if (description != null) {
+ if (getPropertyGetter().getAnnotation(Interpolative.class) != null) {
+ if (!description.endsWith("."))
+ description += ".";
+ description += " <b>NOTE: </b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>. Use <tt>@@</tt> for literal <tt>@</tt>";
+ }
return StringUtils.replace(description, "$docRoot", OneDev.getInstance().getDocRoot());
- else
+ } else {
return null;
+ }
}
}
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/PropertyEditor.java b/server-core/src/main/java/io/onedev/server/web/editable/PropertyEditor.java
index 91dac830c0..f385df1b6c 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/PropertyEditor.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/PropertyEditor.java
@@ -40,10 +40,7 @@ public abstract class PropertyEditor<T> extends ValueEditor<T> {
try {
Validator validator = AppLoader.getInstance(Validator.class);
Set<?> violations = validator.validateValue(
- descriptor.getBeanClass(),
- descriptor.getPropertyName(),
- validatable.getValue());
-
+ descriptor.getBeanClass(), descriptor.getPropertyName(), validatable.getValue());
for (Object each: violations) {
ConstraintViolation<?> violation = (ConstraintViolation<?>) each;
error(violation.getMessage());
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/annotation/Interpolative.java b/server-core/src/main/java/io/onedev/server/web/editable/annotation/Interpolative.java
index dd1433b1e8..1f20780468 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/annotation/Interpolative.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/annotation/Interpolative.java
@@ -25,4 +25,6 @@ public @interface Interpolative {
Class<? extends Payload>[] payload() default {};
+ String exampleVar() default "a";
+
}
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/annotation/Patterns.java b/server-core/src/main/java/io/onedev/server/web/editable/annotation/Patterns.java
index 23f5f3c01c..67b42b2a20 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/annotation/Patterns.java
+++ b/server-core/src/main/java/io/onedev/server/web/editable/annotation/Patterns.java
@@ -17,8 +17,6 @@ public @interface Patterns {
String message() default "";
- boolean interpolative() default false;
-
String suggester() default "";
Class<?>[] groups() default {};
diff --git a/server-core/src/main/java/io/onedev/server/web/editable/code/code-support.js b/server-core/src/main/java/io/onedev/server/web/editable/code/code-support.js
index 1e02e86428..f162ea4a7e 100644
--- a/server-core/src/main/java/io/onedev/server/web/editable/code/code-support.js
+++ b/server-core/src/main/java/io/onedev/server/web/editable/code/code-support.js
@@ -30,7 +30,7 @@ onedev.server.codeSupport = {
var beforeCursor = cm.doc.getLine(line).substring(0, start);
- var escapeFiltered = beforeCursor.replace("\\\\", "").replace("\\@", "");
+ var escapeFiltered = beforeCursor.replace("@@", "");
if ((escapeFiltered.match(/@/g) || []).length % 2 == 1) { // only show hint when type left @
function hint(cm, showHintCallback) {
var end = cm.getCursor().ch;
diff --git a/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.html b/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.html
index 795b443f3a..b47194918b 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.html
+++ b/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.html
@@ -1,3 +1,2 @@
<wicket:extend>
- <a wicket:id="test">test</a>
</wicket:extend>
\ No newline at end of file
diff --git a/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.java b/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.java
index c331d117bb..066be5dd6a 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/test/TestPage.java
@@ -3,7 +3,6 @@ package io.onedev.server.web.page.test;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
-import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import io.onedev.server.web.page.base.BasePage;
@@ -18,14 +17,6 @@ public class TestPage extends BasePage {
@Override
protected void onInitialize() {
super.onInitialize();
-
- add(new Link<Void>("test") {
-
- @Override
- public void onClick() {
- }
-
- });
}
@Override
diff --git a/server-core/src/main/java/org/hibernate/validator/internal/engine/constraintvalidation/ConstraintTree.java b/server-core/src/main/java/org/hibernate/validator/internal/engine/constraintvalidation/ConstraintTree.java
new file mode 100644
index 0000000000..5e65bd22e7
--- /dev/null
+++ b/server-core/src/main/java/org/hibernate/validator/internal/engine/constraintvalidation/ConstraintTree.java
@@ -0,0 +1,543 @@
+/*
+ * Hibernate Validator, declare and validate application constraints
+ *
+ * License: Apache License, Version 2.0
+ * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
+ */
+package org.hibernate.validator.internal.engine.constraintvalidation;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintViolation;
+
+import org.hibernate.validator.constraints.CompositionType;
+import org.hibernate.validator.internal.engine.ValidationContext;
+import org.hibernate.validator.internal.engine.ValueContext;
+import org.hibernate.validator.internal.engine.valuehandling.UnwrapMode;
+import org.hibernate.validator.internal.metadata.core.MetaConstraint;
+import org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl;
+import org.hibernate.validator.internal.util.logging.Log;
+import org.hibernate.validator.internal.util.logging.LoggerFactory;
+import org.hibernate.validator.spi.valuehandling.ValidatedValueUnwrapper;
+
+import io.onedev.commons.utils.ExplicitException;
+import io.onedev.server.util.validation.InterpolativeValidator;
+import io.onedev.server.web.editable.annotation.Interpolative;
+
+import static org.hibernate.validator.constraints.CompositionType.ALL_FALSE;
+import static org.hibernate.validator.constraints.CompositionType.AND;
+import static org.hibernate.validator.constraints.CompositionType.OR;
+import static org.hibernate.validator.internal.util.CollectionHelper.newArrayList;
+import static org.hibernate.validator.internal.util.CollectionHelper.newHashSet;
+
+/**
+ * Due to constraint composition a single constraint annotation can lead to a whole constraint tree being validated.
+ * This class encapsulates such a tree.
+ *
+ * @author Hardy Ferentschik
+ * @author Federico Mancini
+ * @author Dag Hovland
+ * @author Kevin Pollet &lt;[email protected]&gt; (C) 2012 SERLI
+ */
+public class ConstraintTree<A extends Annotation> {
+
+ private static final String TYPE_USE = "TYPE_USE";
+
+ private static final Log log = LoggerFactory.make();
+
+ private final ConstraintTree<?> parent;
+ private final List<ConstraintTree<?>> children;
+
+ /**
+ * The constraint descriptor for the constraint represented by this constraint tree.
+ */
+ private final ConstraintDescriptorImpl<A> descriptor;
+
+ public ConstraintTree(ConstraintDescriptorImpl<A> descriptor) {
+ this( descriptor, null );
+ }
+
+ private ConstraintTree(ConstraintDescriptorImpl<A> descriptor, ConstraintTree<?> parent) {
+ this.parent = parent;
+ this.descriptor = descriptor;
+
+ final Set<ConstraintDescriptorImpl<?>> composingConstraints = descriptor.getComposingConstraintImpls();
+ children = newArrayList( composingConstraints.size() );
+
+ for ( ConstraintDescriptorImpl<?> composingDescriptor : composingConstraints ) {
+ ConstraintTree<?> treeNode = createConstraintTree( composingDescriptor );
+ children.add( treeNode );
+ }
+ }
+
+ private <U extends Annotation> ConstraintTree<U> createConstraintTree(ConstraintDescriptorImpl<U> composingDescriptor) {
+ return new ConstraintTree<U>( composingDescriptor, this );
+ }
+
+ public final List<ConstraintTree<?>> getChildren() {
+ return children;
+ }
+
+ public final ConstraintDescriptorImpl<A> getDescriptor() {
+ return descriptor;
+ }
+
+ public final <T> boolean validateConstraints(ValidationContext<T> executionContext,
+ ValueContext<?, ?> valueContext) {
+ Set<ConstraintViolation<T>> constraintViolations = newHashSet();
+ validateConstraints( executionContext, valueContext, constraintViolations );
+ if ( !constraintViolations.isEmpty() ) {
+ executionContext.addConstraintFailures( constraintViolations );
+ return false;
+ }
+ return true;
+ }
+
+ private <T, V> void validateConstraints(ValidationContext<T> validationContext,
+ ValueContext<?, V> valueContext,
+ Set<ConstraintViolation<T>> constraintViolations) {
+ CompositionResult compositionResult = validateComposingConstraints(
+ validationContext, valueContext, constraintViolations
+ );
+
+ Set<ConstraintViolation<T>> localViolations;
+
+ // After all children are validated the actual ConstraintValidator of the constraint itself is executed
+ if ( mainConstraintNeedsEvaluation( validationContext, constraintViolations ) ) {
+
+ if ( log.isTraceEnabled() ) {
+ log.tracef(
+ "Validating value %s against constraint defined by %s.",
+ valueContext.getCurrentValidatedValue(),
+ descriptor
+ );
+ }
+
+ // find the right constraint validator
+ ConstraintValidator<A, V> validator = getInitializedConstraintValidator( validationContext, valueContext );
+
+ // create a constraint validator context
+ ConstraintValidatorContextImpl constraintValidatorContext = new ConstraintValidatorContextImpl(
+ validationContext.getParameterNames(),
+ validationContext.getTimeProvider(),
+ valueContext.getPropertyPath(),
+ descriptor
+ );
+
+ // validate
+ localViolations = validateSingleConstraint(
+ validationContext,
+ valueContext,
+ constraintValidatorContext,
+ validator
+ );
+
+ // We re-evaluate the boolean composition by taking into consideration also the violations
+ // from the local constraintValidator
+ if ( localViolations.isEmpty() ) {
+ compositionResult.setAtLeastOneTrue( true );
+ }
+ else {
+ compositionResult.setAllTrue( false );
+ }
+ }
+ else {
+ localViolations = Collections.emptySet();
+ }
+
+ if ( !passesCompositionTypeRequirement( constraintViolations, compositionResult ) ) {
+ prepareFinalConstraintViolations(
+ validationContext, valueContext, constraintViolations, localViolations
+ );
+ }
+ }
+
+ private <T, V> ConstraintValidator<A, V> getInitializedConstraintValidator(ValidationContext<T> validationContext,
+ ValueContext<?, V> valueContext) {
+ Type validatedValueType = valueContext.getDeclaredTypeOfValidatedElement();
+ @SuppressWarnings("unchecked")
+ ValidatedValueUnwrapper<V> validatedValueUnwrapper = (ValidatedValueUnwrapper<V>) validationContext
+ .getValidatedValueUnwrapper( validatedValueType );
+
+ // AUTOMATIC mode, need to determine which types of constraint validators are available
+ if ( valueContext.getUnwrapMode().equals( UnwrapMode.AUTOMATIC ) ) {
+ return getConstraintValidatorInstanceForAutomaticUnwrapping(
+ validationContext,
+ valueContext
+ );
+ }
+ // TYPE_USE requires implicitly unwrapping
+ else if ( valueContext.getUnwrapMode().equals( UnwrapMode.UNWRAP )
+ || TYPE_USE.equals( valueContext.getElementType().name() ) ) {
+ return getInitializedValidatorInstanceForWrappedInstance(
+ validationContext,
+ valueContext,
+ validatedValueType,
+ validatedValueUnwrapper
+ );
+
+ }
+ // UnwrapMode.SKIP_UNWRAP
+ else {
+ return getConstraintValidatorNoUnwrapping( validationContext, valueContext );
+ }
+ }
+
+ private <T, V> ConstraintValidator<A, V> getInitializedValidatorInstanceForWrappedInstance(ValidationContext<T> validationContext, ValueContext<?, V> valueContext, Type validatedValueType, ValidatedValueUnwrapper<V> validatedValueUnwrapper) {
+ // make sure that unwrapper is set
+ if ( validatedValueUnwrapper == null ) {
+ throw log.getNoUnwrapperFoundForTypeException(
+ valueContext.getDeclaredTypeOfValidatedElement()
+ .toString()
+ );
+ }
+
+ valueContext.setValidatedValueHandler( validatedValueUnwrapper );
+ validatedValueType = validatedValueUnwrapper.getValidatedValueType( validatedValueType );
+
+ ConstraintValidator<A, V> validator = validationContext.getConstraintValidatorManager()
+ .getInitializedValidator(
+ validatedValueType,
+ descriptor,
+ validationContext.getConstraintValidatorFactory()
+ );
+
+ if ( validator == null ) {
+ throwExceptionForNullValidator( validatedValueType, valueContext.getPropertyPath().asString() );
+ }
+
+ return validator;
+ }
+
+ private void throwExceptionForNullValidator(Type validatedValueType, String path) {
+ if ( descriptor.getConstraintType() == ConstraintDescriptorImpl.ConstraintType.CROSS_PARAMETER ) {
+ throw log.getValidatorForCrossParameterConstraintMustEitherValidateObjectOrObjectArrayException(
+ descriptor.getAnnotationType()
+ .getName()
+ );
+ }
+ else {
+ String className = validatedValueType.toString();
+ if ( validatedValueType instanceof Class ) {
+ Class<?> clazz = (Class<?>) validatedValueType;
+ if ( clazz.isArray() ) {
+ className = clazz.getComponentType().toString() + "[]";
+ }
+ else {
+ className = clazz.getName();
+ }
+ }
+ throw log.getNoValidatorFoundForTypeException( descriptor.getAnnotationType().getName(), className, path );
+ }
+ }
+
+ private <T, V> ConstraintValidator<A, V> getConstraintValidatorInstanceForAutomaticUnwrapping(
+ ValidationContext<T> validationContext,
+ ValueContext<?, V> valueContext
+ ) {
+ Type validatedValueType = valueContext.getDeclaredTypeOfValidatedElement();
+ @SuppressWarnings("unchecked")
+ ValidatedValueUnwrapper<V> validatedValueUnwrapper = (ValidatedValueUnwrapper<V>) validationContext
+ .getValidatedValueUnwrapper( validatedValueType );
+
+ // no unwrapper, get a validator for the validated type
+ if ( validatedValueUnwrapper == null ) {
+ return getConstraintValidatorNoUnwrapping( validationContext, valueContext );
+ }
+
+ // there is an unwrapper - need to find out for which type (wrapper or wrapped value there
+ // are constraint validators available
+ ConstraintValidator<A, V> validatorForWrappedValue = validationContext.getConstraintValidatorManager()
+ .getInitializedValidator(
+ validatedValueUnwrapper.getValidatedValueType( validatedValueType ),
+ descriptor,
+ validationContext.getConstraintValidatorFactory()
+ );
+
+
+ ConstraintValidator<A, V> validatorForWrapper = validationContext.getConstraintValidatorManager()
+ .getInitializedValidator(
+ valueContext.getDeclaredTypeOfValidatedElement(),
+ descriptor,
+ validationContext.getConstraintValidatorFactory()
+ );
+
+ // validator for wrapper and wrapped value is ambiguous -> exception!
+ if ( validatorForWrappedValue != null && validatorForWrapper != null ) {
+ throw log.getConstraintValidatorExistsForWrapperAndWrappedValueException(
+ valueContext.getPropertyPath().toString(),
+ descriptor.getAnnotationType().getName(),
+ validatedValueUnwrapper.getClass().getName()
+ );
+ }
+
+ // neither a validator for wrapper not wrapped value -> exception!
+ if ( validatorForWrappedValue == null && validatorForWrapper == null ) {
+ throw log.getNoValidatorFoundForTypeException(
+ descriptor.getAnnotationType().getName(),
+ validatedValueType.toString(),
+ valueContext.getPropertyPath().toString()
+ );
+ }
+
+ // we have a validator for the wrapped value
+ // -> make sure the unwrapper is set and return proper validator
+ if ( validatorForWrappedValue != null ) {
+ valueContext.setValidatedValueHandler( validatedValueUnwrapper );
+ return validatorForWrappedValue;
+ }
+ else {
+ // there is only a validator for the wrapper type
+ // -> make sure the value handler is unset and return validator for wrapper type
+ valueContext.setValidatedValueHandler( null );
+ return validatorForWrapper;
+ }
+ }
+
+ private <T, V> ConstraintValidator<A, V> getConstraintValidatorNoUnwrapping(ValidationContext<T> validationContext,
+ ValueContext<?, V> valueContext) {
+ // make sure no unwrapper is set
+ valueContext.setValidatedValueHandler( null );
+
+ Type validatedValueType = valueContext.getDeclaredTypeOfValidatedElement();
+ ConstraintValidator<A, V> validator = validationContext.getConstraintValidatorManager()
+ .getInitializedValidator(
+ validatedValueType,
+ descriptor,
+ validationContext.getConstraintValidatorFactory()
+ );
+
+ if ( validator == null ) {
+ throwExceptionForNullValidator( validatedValueType, valueContext.getPropertyPath().asString() );
+ }
+
+ return validator;
+ }
+
+ private <T> boolean mainConstraintNeedsEvaluation(ValidationContext<T> executionContext,
+ Set<ConstraintViolation<T>> constraintViolations) {
+ // we are dealing with a composing constraint with no validator for the main constraint
+ if ( !descriptor.getComposingConstraints().isEmpty() && descriptor.getMatchingConstraintValidatorClasses()
+ .isEmpty() ) {
+ return false;
+ }
+
+ // report as single violation and there is already a violation
+ if ( descriptor.isReportAsSingleViolation() && descriptor.getCompositionType() == AND && !constraintViolations.isEmpty() ) {
+ return false;
+ }
+
+ // explicit fail fast mode
+ if ( executionContext.isFailFastModeEnabled() && !constraintViolations.isEmpty() ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Before the final constraint violations can be reported back we need to check whether we have a composing
+ * constraint whose result should be reported as single violation.
+ *
+ * @param executionContext meta data about top level validation
+ * @param valueContext meta data for currently validated value
+ * @param constraintViolations used to accumulate constraint violations
+ * @param localViolations set of constraint violations of top level constraint
+ */
+ private <T> void prepareFinalConstraintViolations(ValidationContext<T> executionContext,
+ ValueContext<?, ?> valueContext,
+ Set<ConstraintViolation<T>> constraintViolations,
+ Set<ConstraintViolation<T>> localViolations) {
+ if ( reportAsSingleViolation() ) {
+ // We clear the current violations list anyway
+ constraintViolations.clear();
+
+ // But then we need to distinguish whether the local ConstraintValidator has reported
+ // violations or not (or if there is no local ConstraintValidator at all).
+ // If not we create a violation
+ // using the error message in the annotation declaration at top level.
+ if ( localViolations.isEmpty() ) {
+ final String message = (String) getDescriptor().getAttributes().get( "message" );
+ ConstraintViolationCreationContext constraintViolationCreationContext = new ConstraintViolationCreationContext(
+ message,
+ valueContext.getPropertyPath()
+ );
+ ConstraintViolation<T> violation = executionContext.createConstraintViolation(
+ valueContext, constraintViolationCreationContext, descriptor
+ );
+ constraintViolations.add( violation );
+ }
+ }
+
+ // Now, if there were some violations reported by
+ // the local ConstraintValidator, they need to be added to constraintViolations.
+ // Whether we need to report them as a single constraint or just add them to the other violations
+ // from the composing constraints, has been taken care of in the previous conditional block.
+ // This takes also care of possible custom error messages created by the constraintValidator,
+ // as checked in test CustomErrorMessage.java
+ // If no violations have been reported from the local ConstraintValidator, or no such validator exists,
+ // then we just add an empty list.
+ constraintViolations.addAll( localViolations );
+ }
+
+ /**
+ * Validates all composing constraints recursively.
+ *
+ * @param executionContext Meta data about top level validation
+ * @param valueContext Meta data for currently validated value
+ * @param constraintViolations Used to accumulate constraint violations
+ *
+ * @return Returns an instance of {@code CompositionResult} relevant for boolean composition of constraints
+ */
+ private <T> CompositionResult validateComposingConstraints(ValidationContext<T> executionContext,
+ ValueContext<?, ?> valueContext,
+ Set<ConstraintViolation<T>> constraintViolations) {
+ CompositionResult compositionResult = new CompositionResult( true, false );
+ List<ConstraintTree<?>> children = getChildren();
+ for ( ConstraintTree<?> tree : children ) {
+ Set<ConstraintViolation<T>> tmpViolations = newHashSet();
+ tree.validateConstraints( executionContext, valueContext, tmpViolations );
+ constraintViolations.addAll( tmpViolations );
+
+ if ( tmpViolations.isEmpty() ) {
+ compositionResult.setAtLeastOneTrue( true );
+ // no need to further validate constraints, because at least one validation passed
+ if ( descriptor.getCompositionType() == OR ) {
+ break;
+ }
+ }
+ else {
+ compositionResult.setAllTrue( false );
+ if ( descriptor.getCompositionType() == AND
+ && ( executionContext.isFailFastModeEnabled() || descriptor.isReportAsSingleViolation() ) ) {
+ break;
+ }
+ }
+ }
+ return compositionResult;
+ }
+
+ private boolean passesCompositionTypeRequirement(Set<?> constraintViolations, CompositionResult compositionResult) {
+ CompositionType compositionType = getDescriptor().getCompositionType();
+ boolean passedValidation = false;
+ switch ( compositionType ) {
+ case OR:
+ passedValidation = compositionResult.isAtLeastOneTrue();
+ break;
+ case AND:
+ passedValidation = compositionResult.isAllTrue();
+ break;
+ case ALL_FALSE:
+ passedValidation = !compositionResult.isAtLeastOneTrue();
+ break;
+ }
+ assert ( !passedValidation || !( compositionType == AND ) || constraintViolations.isEmpty() );
+ if ( passedValidation ) {
+ constraintViolations.clear();
+ }
+ return passedValidation;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T, V> Set<ConstraintViolation<T>> validateSingleConstraint(ValidationContext<T> executionContext,
+ ValueContext<?, ?> valueContext,
+ ConstraintValidatorContextImpl constraintValidatorContext,
+ ConstraintValidator<A, V> validator) {
+ boolean isValid;
+ try {
+ V validatedValue = (V) valueContext.getCurrentValidatedValue();
+ if (validatedValue != null && !(validator instanceof InterpolativeValidator)) {
+ try {
+ Member member = MetaConstraint.get().getLocation().getMember();
+ if (member instanceof Method) {
+ Method method = (Method) member;
+ Interpolative interpolative = method.getAnnotation(Interpolative.class);
+ if (interpolative != null) {
+ String exampleVar = interpolative.exampleVar();
+ if (valueContext.getCurrentValidatedValue() instanceof Collection) {
+ List<String> list = new ArrayList<>();
+ for (String each: (Collection<String>)validatedValue) {
+ list.add(io.onedev.server.util.interpolative.Interpolative.parse(each).interpolateWith(it->exampleVar));
+ }
+ validatedValue = (V) list;
+ } else {
+ validatedValue = (V) io.onedev.server.util.interpolative.Interpolative.parse(
+ (String) valueContext.getCurrentValidatedValue()).interpolateWith(it->exampleVar);
+ }
+ }
+ }
+ isValid = validator.isValid( validatedValue, constraintValidatorContext );
+ } catch (ExplicitException e) {
+ isValid = true;
+ }
+ } else {
+ isValid = validator.isValid( validatedValue, constraintValidatorContext );
+ }
+ }
+ catch (RuntimeException e) {
+ throw log.getExceptionDuringIsValidCallException( e );
+ }
+ if ( !isValid ) {
+ //We do not add these violations yet, since we don't know how they are
+ //going to influence the final boolean evaluation
+ return executionContext.createConstraintViolations(
+ valueContext, constraintValidatorContext
+ );
+ }
+ return Collections.emptySet();
+ }
+
+ /**
+ * @return {@code} true if the current constraint should be reported as single violation, {@code false otherwise}.
+ * When using negation, we only report the single top-level violation, as
+ * it is hard, especially for ALL_FALSE to give meaningful reports
+ */
+ private boolean reportAsSingleViolation() {
+ return getDescriptor().isReportAsSingleViolation()
+ || getDescriptor().getCompositionType() == ALL_FALSE;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "ConstraintTree" );
+ sb.append( "{ descriptor=" ).append( descriptor );
+ sb.append( ", isRoot=" ).append( parent == null );
+ sb.append( '}' );
+ return sb.toString();
+ }
+
+ private static final class CompositionResult {
+ private boolean allTrue;
+ private boolean atLeastOneTrue;
+
+ CompositionResult(boolean allTrue, boolean atLeastOneTrue) {
+ this.allTrue = allTrue;
+ this.atLeastOneTrue = atLeastOneTrue;
+ }
+
+ public boolean isAllTrue() {
+ return allTrue;
+ }
+
+ public boolean isAtLeastOneTrue() {
+ return atLeastOneTrue;
+ }
+
+ public void setAllTrue(boolean allTrue) {
+ this.allTrue = allTrue;
+ }
+
+ public void setAtLeastOneTrue(boolean atLeastOneTrue) {
+ this.atLeastOneTrue = atLeastOneTrue;
+ }
+ }
+}
diff --git a/server-core/src/main/java/org/hibernate/validator/internal/metadata/core/MetaConstraint.java b/server-core/src/main/java/org/hibernate/validator/internal/metadata/core/MetaConstraint.java
new file mode 100644
index 0000000000..be9c786fd4
--- /dev/null
+++ b/server-core/src/main/java/org/hibernate/validator/internal/metadata/core/MetaConstraint.java
@@ -0,0 +1,150 @@
+/*
+ * Hibernate Validator, declare and validate application constraints
+ *
+ * License: Apache License, Version 2.0
+ * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
+ */
+package org.hibernate.validator.internal.metadata.core;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.util.Set;
+import java.util.Stack;
+
+import org.hibernate.validator.internal.engine.ValidationContext;
+import org.hibernate.validator.internal.engine.ValueContext;
+import org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree;
+import org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl;
+import org.hibernate.validator.internal.metadata.location.ConstraintLocation;
+
+/**
+ * Instances of this class abstract the constraint type (class, method or field constraint) and give access to
+ * meta data about the constraint. This allows a unified handling of constraints in the validator implementation.
+ *
+ * @author Hardy Ferentschik
+ * @author Gunnar Morling
+ */
+public class MetaConstraint<A extends Annotation> {
+
+ private static ThreadLocal<Stack<MetaConstraint<?>>> stack = new ThreadLocal<Stack<MetaConstraint<?>>>() {
+
+ @Override
+ protected Stack<MetaConstraint<?>> initialValue() {
+ return new Stack<MetaConstraint<?>>();
+ }
+
+ };
+
+ public static void push(MetaConstraint<?> constraint) {
+ stack.get().push(constraint);
+ }
+
+ public static void pop() {
+ stack.get().pop();
+ }
+
+ public static MetaConstraint<?> get() {
+ if (!stack.get().isEmpty())
+ return stack.get().peek();
+ else
+ return null;
+ }
+
+ /**
+ * The constraint tree created from the constraint annotation.
+ */
+ private final ConstraintTree<A> constraintTree;
+
+ /**
+ * The constraint descriptor.
+ */
+ private final ConstraintDescriptorImpl<A> constraintDescriptor;
+
+ /**
+ * The location at which this constraint is defined.
+ */
+ private final ConstraintLocation location;
+
+ /**
+ * @param constraintDescriptor The constraint descriptor for this constraint
+ * @param location meta data about constraint placement
+ */
+ public MetaConstraint(ConstraintDescriptorImpl<A> constraintDescriptor, ConstraintLocation location) {
+ this.constraintTree = new ConstraintTree<A>( constraintDescriptor );
+ this.constraintDescriptor = constraintDescriptor;
+ this.location = location;
+ }
+
+ /**
+ * @return Returns the list of groups this constraint is part of. This might include the default group even when
+ * it is not explicitly specified, but part of the redefined default group list of the hosting bean.
+ */
+ public final Set<Class<?>> getGroupList() {
+ return constraintDescriptor.getGroups();
+ }
+
+ public final ConstraintDescriptorImpl<A> getDescriptor() {
+ return constraintDescriptor;
+ }
+
+ public final ElementType getElementType() {
+ return constraintDescriptor.getElementType();
+ }
+
+ public boolean validateConstraint(ValidationContext<?> executionContext, ValueContext<?, ?> valueContext) {
+ push(this);
+ try {
+ valueContext.setElementType( getElementType() );
+ valueContext.setDeclaredTypeOfValidatedElement( location.getTypeForValidatorResolution() );
+
+ boolean validationResult = constraintTree.validateConstraints( executionContext, valueContext );
+ executionContext.markConstraintProcessed( valueContext.getCurrentBean(), valueContext.getPropertyPath(), this );
+
+ return validationResult;
+ } finally {
+ pop();
+ }
+ }
+
+ public ConstraintLocation getLocation() {
+ return location;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ MetaConstraint<?> that = (MetaConstraint<?>) o;
+
+ if ( constraintDescriptor != null ? !constraintDescriptor.equals( that.constraintDescriptor ) : that.constraintDescriptor != null ) {
+ return false;
+ }
+ if ( location != null ? !location.equals( that.location ) : that.location != null ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = constraintDescriptor != null ? constraintDescriptor.hashCode() : 0;
+ result = 31 * result + ( location != null ? location.hashCode() : 0 );
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "MetaConstraint" );
+ sb.append( "{constraintType=" ).append( constraintDescriptor.getAnnotation().annotationType().getName() );
+ sb.append( ", location=" ).append( location );
+ sb.append( "}" );
+ return sb.toString();
+ }
+}
diff --git a/server-core/src/test/java/io/onedev/server/util/interpolative/InterpolativeTest.java b/server-core/src/test/java/io/onedev/server/util/interpolative/InterpolativeTest.java
new file mode 100644
index 0000000000..342c530156
--- /dev/null
+++ b/server-core/src/test/java/io/onedev/server/util/interpolative/InterpolativeTest.java
@@ -0,0 +1,31 @@
+package io.onedev.server.util.interpolative;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class InterpolativeTest {
+
+ @Test
+ public void test() {
+ assertEquals("@", Interpolative.parse("@@").interpolateWith(it->"!"));
+ assertEquals("@@", Interpolative.parse("@@@@").interpolateWith(it->it));
+ assertEquals("hello", Interpolative.parse("@hello@").interpolateWith(it->it));
+ assertEquals("helloworlddo", Interpolative.parse("hello@world@do").interpolateWith(it->it));
+ assertEquals("1234", Interpolative.parse("1@2@@3@4").interpolateWith(it->it));
+ assertEquals("1!!4", Interpolative.parse("1@2@@3@4").interpolateWith(it->"!"));
+ assertEquals("1!-!4", Interpolative.parse("1@2@-@3@4").interpolateWith(it->"!"));
+ try {
+ Interpolative.parse("hello@world@@do");
+ assertTrue(false);
+ } catch (RuntimeException e) {
+ }
+ try {
+ Interpolative.parse("@@@");
+ assertTrue(false);
+ } catch (RuntimeException e) {
+ }
+ }
+
+}
diff --git a/server-core/src/test/java/io/onedev/server/util/patternset/InterpolativePatternSetGrammarTest.java b/server-core/src/test/java/io/onedev/server/util/patternset/InterpolativePatternSetGrammarTest.java
index e623fb2311..7672be6d40 100644
--- a/server-core/src/test/java/io/onedev/server/util/patternset/InterpolativePatternSetGrammarTest.java
+++ b/server-core/src/test/java/io/onedev/server/util/patternset/InterpolativePatternSetGrammarTest.java
@@ -39,13 +39,13 @@ public class InterpolativePatternSetGrammarTest {
assertEquals(expected.getExcludes(), actual.getExcludes());
expected = new PatternSet(Sets.newHashSet("@robin", "-@alive"), Sets.newHashSet("\"@"));
- interpolated = Interpolative.parse("\\@robin \"-\\@alive\" -\\\"\\@").interpolateWith(interpolator);
+ interpolated = Interpolative.parse("@@robin \"-@@alive\" -\\\"@@").interpolateWith(interpolator);
actual = PatternSet.parse(interpolated);
assertEquals(expected.getIncludes(), actual.getIncludes());
assertEquals(expected.getExcludes(), actual.getExcludes());
expected = new PatternSet(Sets.newHashSet("@robin", "hello world", "world"), Sets.newHashSet("hello"));
- interpolated = Interpolative.parse("\\@robin @\"hello world\"@ -@hello world@").interpolateWith(interpolator);
+ interpolated = Interpolative.parse("@@robin @\"hello world\"@ -@hello world@").interpolateWith(interpolator);
actual = PatternSet.parse(interpolated);
assertEquals(expected.getIncludes(), actual.getIncludes());
assertEquals(expected.getExcludes(), actual.getExcludes());
diff --git a/server-plugin/server-plugin-buildspec-node/src/main/java/io/onedev/server/plugin/buildspec/node/NodeJobSuggestion.java b/server-plugin/server-plugin-buildspec-node/src/main/java/io/onedev/server/plugin/buildspec/node/NodeJobSuggestion.java
index 8e1e568e0f..b962d832a5 100644
--- a/server-plugin/server-plugin-buildspec-node/src/main/java/io/onedev/server/plugin/buildspec/node/NodeJobSuggestion.java
+++ b/server-plugin/server-plugin-buildspec-node/src/main/java/io/onedev/server/plugin/buildspec/node/NodeJobSuggestion.java
@@ -61,7 +61,7 @@ public class NodeJobSuggestion implements JobSuggestion {
"echo \"##onedev[SetBuildVersion '@" + VariableInterpolator.PREFIX_SCRIPTS + GroovyScript.BUILTIN_PREFIX + DETERMINE_PROJECT_VERSION + "@']\"",
"echo",
"npm install",
- "npm install \\@angular/cli");
+ "npm install @@angular/cli");
if (jsonNode.has("scripts")) {
JsonNode jsonScripts = jsonNode.get("scripts");
diff --git a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/JobHtmlReport.java b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/JobHtmlReport.java
index feca9e2cc7..10937b9a99 100644
--- a/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/JobHtmlReport.java
+++ b/server-plugin/server-plugin-report-html/src/main/java/io/onedev/server/plugin/report/html/JobHtmlReport.java
@@ -28,8 +28,7 @@ public class JobHtmlReport extends JobReport {
private String startPage;
- @Editable(order=1100, description="Specify start page of the report relative to <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>, for instance: api/index.html. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=1100, description="Specify start page of the report relative to <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>, for instance: api/index.html")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getStartPage() {
diff --git a/server-plugin/server-plugin-report-jest/src/main/java/io/onedev/server/plugin/report/jest/JobJestReport.java b/server-plugin/server-plugin-report-jest/src/main/java/io/onedev/server/plugin/report/jest/JobJestReport.java
index 3e0d14f400..0540290b50 100644
--- a/server-plugin/server-plugin-report-jest/src/main/java/io/onedev/server/plugin/report/jest/JobJestReport.java
+++ b/server-plugin/server-plugin-report-jest/src/main/java/io/onedev/server/plugin/report/jest/JobJestReport.java
@@ -33,10 +33,9 @@ public class JobJestReport extends JobReport {
public static final String DIR = "jest-reports";
@Editable(order=100, description="Specify json file containing Jest test results relative to OneDev workspace. "
- + "It can be generated via Jest option <tt>--json</tt> and <tt>--outputFile</tt>. Use * or ? for pattern match. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ + "It can be generated via Jest option <tt>--json</tt> and <tt>--outputFile</tt>. Use * or ? for pattern match")
@Interpolative(variableSuggester="suggestVariables")
- @Patterns(interpolative = true, path=true)
+ @Patterns(path=true)
@NotEmpty
@Override
public String getFilePatterns() {
diff --git a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/JobMarkdownReport.java b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/JobMarkdownReport.java
index 9678d0d9b7..b060417734 100644
--- a/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/JobMarkdownReport.java
+++ b/server-plugin/server-plugin-report-markdown/src/main/java/io/onedev/server/plugin/report/markdown/JobMarkdownReport.java
@@ -28,8 +28,7 @@ public class JobMarkdownReport extends JobReport {
private String startPage;
- @Editable(order=1100, description="Specify start page of the report relative to <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>, for instance: <tt>manual/index.md</tt>. "
- + "<b>Note:</b> Type <tt>@</tt> to <a href='$docRoot/pages/variable-substitution.md' target='_blank' tabindex='-1'>insert variable</a>, use <tt>\\</tt> to escape normal occurrences of <tt>@</tt> or <tt>\\</tt>")
+ @Editable(order=1100, description="Specify start page of the report relative to <a href='$docRoot/pages/concepts.md#job-workspace' target='_blank'>job workspace</a>, for instance: <tt>manual/index.md</tt>")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getStartPage() {