4
4
import java .util .Objects ;
5
5
6
6
import io .quarkus .builder .item .MultiBuildItem ;
7
+ import io .quarkus .qute .runtime .QuteConfig ;
7
8
8
9
/**
9
10
* Discovered template.
10
11
* <p>
11
12
* Templates backed by files located in a template root are discovered automatically. Furthermore, extensions can produce this
12
13
* build item in order to provide a template that is not backed by a file.
13
14
*
15
+ * <h2>Warning</h2>
16
+ *
17
+ * Extensions should never <i>consume</i> this build item directly. However, they may consume the
18
+ * {@link EffectiveTemplatePathsBuildItem} instead.
19
+ *
14
20
* @see TemplateRootBuildItem
15
21
*/
16
22
public final class TemplatePathBuildItem extends MultiBuildItem {
17
23
24
+ /**
25
+ * The priority used for templates from the root application archive.
26
+ */
27
+ public static final int ROOT_ARCHIVE_PRIORITY = 30 ;
28
+
29
+ /**
30
+ * The default priority used for templates that are not backed by a file.
31
+ */
32
+ public static final int BUILD_ITEM_PRIORITY = 20 ;
33
+
34
+ /**
35
+ * The priority used for templates from non-root application archives.
36
+ */
37
+ public static final int APP_ARCHIVE_PRIORITY = 10 ;
38
+
18
39
/**
19
40
*
20
41
* @return a new builder instance
@@ -30,23 +51,27 @@ public static Builder builder() {
30
51
private final Path fullPath ;
31
52
private final String extensionInfo ;
32
53
54
+ private final int priority ;
55
+
33
56
/**
34
57
*
35
58
* @param path
36
59
* @param fullPath
37
60
* @param content
38
61
* @deprecated Use the {@link #builder()} instead
39
62
*/
40
- @ Deprecated
63
+ @ Deprecated ( forRemoval = true , since = "3.13" )
41
64
public TemplatePathBuildItem (String path , Path fullPath , String content ) {
42
- this (Objects .requireNonNull (path ), Objects .requireNonNull (content ), Objects .requireNonNull (fullPath ), null );
65
+ this (Objects .requireNonNull (path ), Objects .requireNonNull (content ), Objects .requireNonNull (fullPath ), null ,
66
+ BUILD_ITEM_PRIORITY );
43
67
}
44
68
45
- private TemplatePathBuildItem (String path , String content , Path fullPath , String extensionInfo ) {
69
+ private TemplatePathBuildItem (String path , String content , Path fullPath , String extensionInfo , int priority ) {
46
70
this .path = path ;
47
71
this .content = content ;
48
72
this .fullPath = fullPath ;
49
73
this .extensionInfo = extensionInfo ;
74
+ this .priority = priority ;
50
75
}
51
76
52
77
/**
@@ -86,6 +111,15 @@ public String getExtensionInfo() {
86
111
return extensionInfo ;
87
112
}
88
113
114
+ /**
115
+ * Templates with higher priority take precedence when duplicates are found.
116
+ *
117
+ * @return the priority
118
+ */
119
+ public int getPriority () {
120
+ return priority ;
121
+ }
122
+
89
123
/**
90
124
*
91
125
* @return {@code true} if it represents a user tag, {@code false} otherwise
@@ -111,7 +145,7 @@ public boolean isFileBased() {
111
145
}
112
146
113
147
public String getSourceInfo () {
114
- return isFileBased () ? getFullPath ().toString () : extensionInfo ;
148
+ return ( isFileBased () ? getFullPath ().toString () : extensionInfo ) + " [" + getPriority () + "]" ;
115
149
}
116
150
117
151
public static class Builder {
@@ -120,6 +154,7 @@ public static class Builder {
120
154
private String content ;
121
155
private Path fullPath ;
122
156
private String extensionInfo ;
157
+ private int priority = BUILD_ITEM_PRIORITY ;
123
158
124
159
/**
125
160
* Set the path relative to the template root. The {@code /} is used as a path separator.
@@ -168,11 +203,23 @@ public Builder extensionInfo(String info) {
168
203
return this ;
169
204
}
170
205
206
+ /**
207
+ * Set the priority of the template.
208
+ *
209
+ * @param priority
210
+ * @return self
211
+ * @see QuteConfig#duplicitTemplateStrategy()
212
+ */
213
+ public Builder priority (int priority ) {
214
+ this .priority = priority ;
215
+ return this ;
216
+ }
217
+
171
218
public TemplatePathBuildItem build () {
172
219
if (fullPath == null && extensionInfo == null ) {
173
220
throw new IllegalStateException ("Templates that are not backed by a file must provide extension info" );
174
221
}
175
- return new TemplatePathBuildItem (path , content , fullPath , extensionInfo );
222
+ return new TemplatePathBuildItem (path , content , fullPath , extensionInfo , priority );
176
223
}
177
224
178
225
}
0 commit comments