Skip to content

Commit

Permalink
4.x: Update to static content (#9502)
Browse files Browse the repository at this point in the history
* Static content update
- WebServer feature to support static content from configuration
- new Builder API based prototypes to configure it
- deprecated old approach

* Use defaults for sockets and welcome file.
Added singular methods for classpath and path handlers.
Renamed welcome file to welcome to align with current MP configuration option.

* CDI extension update to use new API with same defaults,
update to deprecated usages to avoid compiler warnings.

* Documentation update for MP and SE.

* Fix classpath root cleanup.
Fix configuration used in MP extension.

* Introduction of io.helidon.common.Size to handle size strings (similar to Java's Duration, but for size in bytes).
Update to builder to support nice defaults for size.
Update to PR to fix comments, and use Size for memory cache capacity.
  • Loading branch information
tomas-langer authored Nov 25, 2024
1 parent a5868d6 commit 8399b14
Show file tree
Hide file tree
Showing 43 changed files with 2,827 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.helidon.codegen.classmodel.InnerClass;
import io.helidon.codegen.classmodel.Javadoc;
import io.helidon.codegen.classmodel.Method;
import io.helidon.common.Size;
import io.helidon.common.types.AccessModifier;
import io.helidon.common.types.TypeName;
import io.helidon.common.types.TypeNames;
Expand Down Expand Up @@ -220,8 +221,14 @@ Consumer<ContentBuilder<?>> toDefaultValue(String defaultValue) {
.addContent(defaultValue)
.addContent("\"");
}
if (TypeNames.SIZE.equals(typeName)) {
CodegenValidator.validateSize(enclosingType, annotatedMethod, OPTION_DEFAULT, "value", defaultValue);
return content -> content.addContent(Size.class)
.addContent(".parse(\"")
.addContent(defaultValue)
.addContent("\")");
}
if (TypeNames.DURATION.equals(typeName)) {

CodegenValidator.validateDuration(enclosingType, annotatedMethod, OPTION_DEFAULT, "value", defaultValue);
return content -> content.addContent(Duration.class)
.addContent(".parse(\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.URI;
import java.time.Duration;

import io.helidon.common.Size;
import io.helidon.common.types.TypeName;
import io.helidon.common.types.TypedElementInfo;

Expand Down Expand Up @@ -86,4 +87,35 @@ public static String validateDuration(TypeName enclosingType,
element.originatingElementValue());
}
}

/**
* Validate a {@link io.helidon.common.Size} annotation on a method, field, or constructor.
*
* @param enclosingType type that owns the element
* @param element annotated element
* @param annotationType type of annotation
* @param property property of annotation
* @param value actual value read from the annotation property
* @return the value
* @throws io.helidon.codegen.CodegenException with correct source element describing the problem
*/
public static String validateSize(TypeName enclosingType,
TypedElementInfo element,
TypeName annotationType,
String property,
String value) {
try {
Size.parse(value);
return value;
} catch (Exception e) {
throw new CodegenException("Size expression of annotation " + annotationType.fqName() + "."
+ property + "(): "
+ "\"" + value + "\" cannot be parsed. Size expects an"
+ " expression such as '120 KB' (120 * 1024 * 1024), "
+ "'120 kB' (120 * 1000 * 1000), or '120 KiB' (same as KB)"
+ " Please check javadoc of " + Size.class.getName() + " class.",
e,
element.originatingElementValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public abstract class TypeInfoFactoryBase {
TypeName.create(Target.class),
TypeName.create(Retention.class),
TypeName.create(Repeatable.class));
private static final Set<String> ACCESS_MODIFIERS = Set.of("PUBLIC", "PRIVATE", "PROTECTED");

/**
* There are no side effects of this constructor.
Expand Down Expand Up @@ -144,10 +145,15 @@ protected static Set<io.helidon.common.types.Modifier> modifiers(CodegenContext
Set<io.helidon.common.types.Modifier> result = new HashSet<>();

for (String stringModifier : stringModifiers) {
String upperCased = stringModifier.toUpperCase(Locale.ROOT);
if (ACCESS_MODIFIERS.contains(upperCased)) {
// ignore access modifiers, as they are handled elsewhere
continue;
}
try {
result.add(io.helidon.common.types.Modifier.valueOf(stringModifier.toUpperCase(Locale.ROOT)));
result.add(io.helidon.common.types.Modifier.valueOf(upperCased));
} catch (Exception ignored) {
// we do not care about modifiers we do not understand - either access modifier, or something new
// we do not care about modifiers we do not understand
ctx.logger().log(System.Logger.Level.TRACE,
"Modifier " + stringModifier + " not understood by type info factory.");
}
Expand Down
Loading

0 comments on commit 8399b14

Please sign in to comment.