Skip to content

Commit 08a8360

Browse files
committed
format
1 parent cd2607d commit 08a8360

File tree

64 files changed

+1031
-759
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1031
-759
lines changed

avaje-jex-freemarker/src/test/java/io/avaje/jex/render/freemarker/FreeMarkerServiceLoaderTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ class FreeMarkerServiceLoaderTest {
1414
static TestPair pair = init();
1515

1616
static TestPair init() {
17-
var app = Jex.create().routing(routing -> routing.get("/noModel", ctx -> ctx.render("one.ftl"))
18-
.get("/withModel", ctx -> ctx.render("two.ftl", Map.of("message", "hello"))));
17+
var app =
18+
Jex.create()
19+
.routing(
20+
routing ->
21+
routing
22+
.get("/noModel", ctx -> ctx.render("one.ftl"))
23+
.get(
24+
"/withModel",
25+
ctx -> ctx.render("two.ftl", Map.of("message", "hello"))));
1926
// not explicitly registered so auto registered via service loader
2027
return TestPair.create(app);
2128
}

avaje-jex-htmx/src/main/java/io/avaje/jex/htmx/HxHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/**
66
* Wrap a Handler with filtering for Htmx specific headers.
77
*
8-
* <p>The underlying Handler will not be invoked unless the request is a Htmx request and matches the required
9-
* attributes.
8+
* <p>The underlying Handler will not be invoked unless the request is a Htmx request and matches
9+
* the required attributes.
1010
*/
1111
public interface HxHandler {
1212

avaje-jex-mustache/src/test/java/io/avaje/jex/render/mustache/MustacheRenderTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ class MustacheRenderTest {
1515
static TestPair pair1 = init(false);
1616

1717
static TestPair init(boolean explicit) {
18-
var app = Jex.create().routing(routing -> routing.get("/noModel", ctx -> ctx.render("one.mustache"))
19-
.get("/withModel", ctx -> ctx.render("two.mustache", Map.of("message", "hello"))));
18+
var app =
19+
Jex.create()
20+
.routing(
21+
routing ->
22+
routing
23+
.get("/noModel", ctx -> ctx.render("one.mustache"))
24+
.get(
25+
"/withModel",
26+
ctx -> ctx.render("two.mustache", Map.of("message", "hello"))));
2027
if (explicit) {
2128
app.register(new MustacheRender(), "mustache");
2229
}

avaje-jex-static-content/src/main/java/io/avaje/jex/staticcontent/AbstractStaticHandler.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ protected String getExt(String path) {
7070

7171
protected String lookupMime(String path) {
7272
var lower = path.toLowerCase();
73-
return Objects.requireNonNullElseGet(MIME_MAP.getContentTypeFor(path), () -> {
74-
String ext = getExt(lower);
75-
return mimeTypes.getOrDefault(ext, "application/octet-stream");
76-
});
73+
return Objects.requireNonNullElseGet(
74+
MIME_MAP.getContentTypeFor(path),
75+
() -> {
76+
String ext = getExt(lower);
77+
return mimeTypes.getOrDefault(ext, "application/octet-stream");
78+
});
7779
}
7880

7981
protected boolean isCached(final String path) {

avaje-jex-static-content/src/main/java/io/avaje/jex/staticcontent/ClassResourceLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
/**
66
* Loading resources from the classpath or module path.
77
*
8-
* <p>When not specified Avaje Jex provides a default implementation that looks to find resources using the class loader
9-
* associated with the ClassResourceLoader.
8+
* <p>When not specified Avaje Jex provides a default implementation that looks to find resources
9+
* using the class loader associated with the ClassResourceLoader.
1010
*
11-
* <p>As a fallback, {@link ClassLoader#getSystemResourceAsStream(String)} is used if the loader returns null.
11+
* <p>As a fallback, {@link ClassLoader#getSystemResourceAsStream(String)} is used if the loader
12+
* returns null.
1213
*/
1314
public interface ClassResourceLoader {
1415

avaje-jex-static-content/src/main/java/io/avaje/jex/staticcontent/DefaultResourceLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ public URL loadResource(String resourcePath) {
2121
var url = clazz.getResource(resourcePath);
2222
if (url == null) {
2323
// search the module path for top level resource
24-
url = Optional.ofNullable(ClassLoader.getSystemResource(resourcePath))
25-
.orElseGet(
26-
() -> Thread.currentThread().getContextClassLoader().getResource(resourcePath));
24+
url =
25+
Optional.ofNullable(ClassLoader.getSystemResource(resourcePath))
26+
.orElseGet(
27+
() -> Thread.currentThread().getContextClassLoader().getResource(resourcePath));
2728
}
2829
return Objects.requireNonNull(url, "Unable to locate resource: " + resourcePath);
2930
}

avaje-jex-static-content/src/main/java/io/avaje/jex/staticcontent/StaticClassResourceHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ final class StaticClassResourceHandler extends AbstractStaticHandler {
2424
URL singleFile,
2525
boolean precompress,
2626
CompressionConfig compressionConfig) {
27-
super(urlPrefix, filesystemRoot, mimeTypes, headers, skipFilePredicate, precompress, compressionConfig);
27+
super(
28+
urlPrefix,
29+
filesystemRoot,
30+
mimeTypes,
31+
headers,
32+
skipFilePredicate,
33+
precompress,
34+
compressionConfig);
2835

2936
this.resourceLoader = resourceLoader;
3037
this.indexFile = indexFile;

avaje-jex-static-content/src/main/java/io/avaje/jex/staticcontent/StaticFileHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ final class StaticFileHandler extends AbstractStaticHandler {
2525
File singleFile,
2626
boolean precompress,
2727
CompressionConfig compressionConfig) {
28-
super(urlPrefix, filesystemRoot, mimeTypes, headers, skipFilePredicate, precompress, compressionConfig);
28+
super(
29+
urlPrefix,
30+
filesystemRoot,
31+
mimeTypes,
32+
headers,
33+
skipFilePredicate,
34+
precompress,
35+
compressionConfig);
2936
this.indexFile = welcomeFile;
3037
this.singleFile = singleFile;
3138
}

avaje-jex-static-content/src/main/java/io/avaje/jex/staticcontent/StaticResourceHandlerBuilder.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
final class StaticResourceHandlerBuilder implements StaticContent.Builder, StaticContent {
1616

1717
private static final String FAILED_TO_LOCATE_FILE = "Failed to locate file: ";
18-
private static final String DIRECTORY_INDEX_FAILURE = "Failed to locate Directory Index Resource: ";
18+
private static final String DIRECTORY_INDEX_FAILURE =
19+
"Failed to locate Directory Index Resource: ";
1920
private static final Predicate<Context> NO_OP_PREDICATE = ctx -> false;
2021
private static final ClassResourceLoader DEFAULT_LOADER = new DefaultResourceLoader();
2122

@@ -49,17 +50,20 @@ public StaticContent build() {
4950
}
5051

5152
ExchangeHandler createHandler(CompressionConfig compress) {
52-
path = Objects.requireNonNull(path)
53-
.transform(this::prependSlash)
54-
.transform(s -> s.endsWith("/*") ? s.substring(0, s.length() - 2) : s);
53+
path =
54+
Objects.requireNonNull(path)
55+
.transform(this::prependSlash)
56+
.transform(s -> s.endsWith("/*") ? s.substring(0, s.length() - 2) : s);
5557

5658
root = isClasspath ? root.transform(this::prependSlash) : root;
5759
if (isClasspath && "/".equals(root)) {
58-
throw new IllegalArgumentException("Cannot serve full classpath, please configure a classpath prefix");
60+
throw new IllegalArgumentException(
61+
"Cannot serve full classpath, please configure a classpath prefix");
5962
}
6063

6164
if (root.endsWith("/") && directoryIndex == null) {
62-
throw new IllegalArgumentException("Directory Index file is required when serving directories");
65+
throw new IllegalArgumentException(
66+
"Directory Index file is required when serving directories");
6367
}
6468

6569
if (!isClasspath) {
@@ -147,7 +151,15 @@ private StaticFileHandler fileLoader(CompressionConfig compress) {
147151
}
148152

149153
return new StaticFileHandler(
150-
path, fsRoot, mimeTypes, headers, skipFilePredicate, dirIndex, singleFile, precompress, compress);
154+
path,
155+
fsRoot,
156+
mimeTypes,
157+
headers,
158+
skipFilePredicate,
159+
dirIndex,
160+
singleFile,
161+
precompress,
162+
compress);
151163
}
152164

153165
private StaticClassResourceHandler classPathHandler(CompressionConfig compress) {

avaje-jex-static-content/src/main/java/module-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Defines the Static Content API for serving static resources with Jex - see
3-
* {@link io.avaje.jex.staticcontent.StaticContent}.
2+
* Defines the Static Content API for serving static resources with Jex - see {@link
3+
* io.avaje.jex.staticcontent.StaticContent}.
44
*
55
* <pre>{@code
66
* var staticContent = StaticContentService.createCP("/public").httpPath("/").directoryIndex("index.html");

avaje-jex-test/src/main/java/io/avaje/jex/test/JexInjectPlugin.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
/**
1111
* avaje-inject-test plugin that:
1212
*
13-
* <p>- Detects when a http client is being used in a test - Starts Jex server on random port - Creates the appropriate
14-
* client for the port (to be injected into the test class) - Shutdown the server on test completion (Plugin.Scope
15-
* close)
13+
* <p>- Detects when a http client is being used in a test - Starts Jex server on random port -
14+
* Creates the appropriate client for the port (to be injected into the test class) - Shutdown the
15+
* server on test completion (Plugin.Scope close)
1616
*/
1717
public final class JexInjectPlugin implements Plugin {
1818

@@ -57,21 +57,19 @@ private static class LocalScope implements Plugin.Scope {
5757
private final HttpClient httpClient;
5858

5959
LocalScope(BeanScope beanScope) {
60-
Jex jex = beanScope
61-
.getOptional(Jex.class)
62-
.orElse(Jex.create())
63-
.configureWith(beanScope)
64-
.port(0);
60+
Jex jex =
61+
beanScope.getOptional(Jex.class).orElse(Jex.create()).configureWith(beanScope).port(0);
6562

6663
// get a HttpClientContext.Builder provided by dependency injection test scope or new one up
6764
this.server = jex.start();
6865
int port = server.port();
69-
this.httpClient = beanScope
70-
.getOptional(HttpClient.Builder.class)
71-
.orElse(HttpClient.builder())
72-
.configureWith(beanScope)
73-
.baseUrl("http://localhost:" + port)
74-
.build();
66+
this.httpClient =
67+
beanScope
68+
.getOptional(HttpClient.Builder.class)
69+
.orElse(HttpClient.builder())
70+
.configureWith(beanScope)
71+
.baseUrl("http://localhost:" + port)
72+
.build();
7573
}
7674

7775
@Override

avaje-jex/src/main/java/io/avaje/jex/AppLifecycle.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ enum Status {
2121
void onShutdown(Runnable onShutdown);
2222

2323
/**
24-
* Registers a runnable to be executed when the application server is shutting down, with a specific order.
24+
* Registers a runnable to be executed when the application server is shutting down, with a
25+
* specific order.
2526
*
2627
* <p>Runnables with lower order values will be executed first.
2728
*
@@ -35,7 +36,8 @@ enum Status {
3536
/**
3637
* Registers a runnable as a shutdown hook with the JVM.
3738
*
38-
* <p>This runnable will be executed when the JVM is shutting down, regardless of the application server's state.
39+
* <p>This runnable will be executed when the JVM is shutting down, regardless of the application
40+
* server's state.
3941
*
4042
* @param onShutdown The runnable to register as a shutdown hook.
4143
*/

avaje-jex/src/main/java/io/avaje/jex/DJexConfig.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,20 @@ public String contextPath() {
4848
public JexConfig contextPath(String contextPath) {
4949
if (!this.contextPath.equals(contextPath)) {
5050

51-
this.contextPath = contextPath
52-
.transform(s -> s.startsWith("/") ? s : "/" + s)
53-
.transform(s -> s.endsWith("/") ? s.substring(0, s.lastIndexOf("/")) : s);
51+
this.contextPath =
52+
contextPath
53+
.transform(s -> s.startsWith("/") ? s : "/" + s)
54+
.transform(s -> s.endsWith("/") ? s.substring(0, s.lastIndexOf("/")) : s);
5455
}
5556
return this;
5657
}
5758

5859
@Override
5960
public Executor executor() {
6061
if (executor == null) {
61-
executor = Executors.newThreadPerTaskExecutor(
62-
Thread.ofVirtual().name("avaje-jex-http-", 0).factory());
62+
executor =
63+
Executors.newThreadPerTaskExecutor(
64+
Thread.ofVirtual().name("avaje-jex-http-", 0).factory());
6365
}
6466
return executor;
6567
}

avaje-jex/src/main/java/io/avaje/jex/DefaultRouting.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public Map<Class<?>, ExceptionHandler<?>> errorHandlers() {
3636
}
3737

3838
private String path(String path) {
39-
return String.join("", pathDeque) + ((path.startsWith("/") || path.isEmpty()) ? path : "/" + path);
39+
return String.join("", pathDeque)
40+
+ ((path.startsWith("/") || path.isEmpty()) ? path : "/" + path);
4041
}
4142

4243
private void addEndpoints(String path, HttpService group) {

avaje-jex/src/main/java/io/avaje/jex/Jex.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ default Jex after(Consumer<Context> handler) {
173173
}
174174

175175
/**
176-
* Registers an exception handler that handles the given type of exceptions. This will replace an existing error
177-
* handler for the same exception class.
176+
* Registers an exception handler that handles the given type of exceptions. This will replace an
177+
* existing error handler for the same exception class.
178178
*
179179
* @param exceptionClass the type of exception to handle by this handler
180180
* @param handler the error handler
@@ -221,8 +221,8 @@ default Jex group(String path, HttpService group) {
221221
/**
222222
* Configures the Jex instance using a dependency injection scope from Avaje-Inject.
223223
*
224-
* <p>This method allows you to leverage the Avaje-Inject framework to provide dependencies like Handlers,
225-
* StaticResources, and Plugins to the Jex instance.
224+
* <p>This method allows you to leverage the Avaje-Inject framework to provide dependencies like
225+
* Handlers, StaticResources, and Plugins to the Jex instance.
226226
*
227227
* @param beanScope The Avaje-Inject BeanScope containing the dependencies.
228228
* @return The configured Jex instance.
@@ -232,8 +232,8 @@ default Jex group(String path, HttpService group) {
232232
/**
233233
* Configures the Jex instance using a functional approach.
234234
*
235-
* <p>The provided consumer lambda allows you to customize the Jex configuration, such as setting the port,
236-
* compression, and other options.
235+
* <p>The provided consumer lambda allows you to customize the Jex configuration, such as setting
236+
* the port, compression, and other options.
237237
*
238238
* @param configure A consumer lambda that accepts a {@link JexConfig} instance for configuration.
239239
* @return The configured Jex instance.
@@ -243,7 +243,8 @@ default Jex group(String path, HttpService group) {
243243
/**
244244
* Sets the port number on which the Jex server will listen for incoming requests.
245245
*
246-
* <p>The default value is 8080. If The port is set to 0, the server will randomly choose an available port.
246+
* <p>The default value is 8080. If The port is set to 0, the server will randomly choose an
247+
* available port.
247248
*
248249
* @param port The port number to use.
249250
*/
@@ -262,8 +263,8 @@ default Jex group(String path, HttpService group) {
262263
/**
263264
* Explicitly register a template renderer.
264265
*
265-
* <p>Note that if not explicitly registered TemplateRender's can be automatically registered via ServiceLoader just
266-
* by including them to the class path.
266+
* <p>Note that if not explicitly registered TemplateRender's can be automatically registered via
267+
* ServiceLoader just by including them to the class path.
267268
*
268269
* @param renderer The template renderer to register
269270
* @param extensions The extensions the renderer is used for
@@ -283,7 +284,8 @@ default Jex group(String path, HttpService group) {
283284
interface Server {
284285

285286
/**
286-
* Register a function to execute LAST on shutdown after all the normal lifecycle shutdown functions have run.
287+
* Register a function to execute LAST on shutdown after all the normal lifecycle shutdown
288+
* functions have run.
287289
*
288290
* <p>Typically, we desire to shut down logging (e.g. Log4J) last.
289291
*/

0 commit comments

Comments
 (0)