Skip to content

Commit c879113

Browse files
committed
format
1 parent cd2607d commit c879113

File tree

72 files changed

+1093
-806
lines changed

Some content is hidden

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

72 files changed

+1093
-806
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/StaticContent.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package io.avaje.jex.staticcontent;
22

3-
import java.net.URLConnection;
4-
import java.util.function.Predicate;
5-
63
import io.avaje.jex.http.Context;
74
import io.avaje.jex.security.Role;
85
import io.avaje.jex.spi.JexPlugin;
6+
import java.net.URLConnection;
7+
import java.util.function.Predicate;
98

109
/**
1110
* Static content resource handler.

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-static-content/src/test/java/io/avaje/jex/staticcontent/CompressedStaticFileTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5+
import io.avaje.jex.Jex;
6+
import io.avaje.jex.test.TestPair;
57
import java.net.http.HttpResponse;
68
import java.time.Duration;
7-
89
import org.junit.jupiter.api.AfterAll;
910
import org.junit.jupiter.api.Test;
1011

11-
import io.avaje.jex.Jex;
12-
import io.avaje.jex.test.TestPair;
13-
1412
class CompressedStaticFileTest {
1513

1614
static TestPair pair = init();
@@ -28,7 +26,8 @@ static TestPair init() {
2826
.plugin(StaticContent.ofClassPath("/logback.xml").route("/single").build())
2927
.plugin(
3028
StaticContent.ofFile("src/test/resources/logback.xml")
31-
.route("/singleFile").build());
29+
.route("/singleFile")
30+
.build());
3231

3332
return TestPair.create(app);
3433
}
@@ -40,9 +39,7 @@ private static StaticContent.Builder defaultFile() {
4039
}
4140

4241
private static StaticContent.Builder defaultCP() {
43-
return StaticContent.ofClassPath("/public")
44-
.directoryIndex("index.html")
45-
.preCompress();
42+
return StaticContent.ofClassPath("/public").directoryIndex("index.html").preCompress();
4643
}
4744

4845
@AfterAll

avaje-jex-static-content/src/test/java/io/avaje/jex/staticcontent/StaticFileTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5+
import io.avaje.jex.Jex;
6+
import io.avaje.jex.test.TestPair;
57
import java.net.http.HttpResponse;
68
import java.time.Duration;
7-
89
import org.junit.jupiter.api.AfterAll;
910
import org.junit.jupiter.api.Test;
1011

11-
import io.avaje.jex.Jex;
12-
import io.avaje.jex.test.TestPair;
13-
1412
class StaticFileTest {
1513

1614
static TestPair pair = init();
@@ -28,14 +26,14 @@ static TestPair init() {
2826
.plugin(StaticContent.ofClassPath("/logback.xml").route("/single").build())
2927
.plugin(
3028
StaticContent.ofFile("src/test/resources/logback.xml")
31-
.route("/singleFile").build());
29+
.route("/singleFile")
30+
.build());
3231

3332
return TestPair.create(app);
3433
}
3534

3635
private static StaticContent.Builder defaultFile() {
37-
return StaticContent.ofFile("src/test/resources/public")
38-
.directoryIndex("index.html");
36+
return StaticContent.ofFile("src/test/resources/public").directoryIndex("index.html");
3937
}
4038

4139
private static StaticContent.Builder defaultCP() {

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-test/src/main/java/io/avaje/jex/test/TestPair.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package io.avaje.jex.test;
22

3-
import java.net.http.HttpClient.Version;
4-
53
import io.avaje.http.client.HttpClient;
64
import io.avaje.http.client.HttpClientRequest;
75
import io.avaje.jex.Jex;
6+
import java.net.http.HttpClient.Version;
87

98
/** Server and Client pair for a test. */
109
public class TestPair {

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) {

0 commit comments

Comments
 (0)