Skip to content

Commit f27f23b

Browse files
committed
minor improvements
1 parent 697e685 commit f27f23b

File tree

177 files changed

+2795
-3836
lines changed

Some content is hidden

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

177 files changed

+2795
-3836
lines changed

wicket-spring-boot-context/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<artifactId>spring-context-support</artifactId>
3131
<scope>provided</scope>
3232
</dependency>
33+
<dependency>
34+
<groupId>org.projectlombok</groupId>
35+
<artifactId>lombok</artifactId>
36+
<scope>provided</scope>
37+
</dependency>
3338
<dependency>
3439
<groupId>org.springframework.boot</groupId>
3540
<artifactId>spring-boot-autoconfigure</artifactId>
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,48 @@
11
package com.giffing.wicket.spring.boot.context.condition;
22

3-
import java.lang.annotation.Documented;
4-
import java.lang.annotation.ElementType;
5-
import java.lang.annotation.Retention;
6-
import java.lang.annotation.RetentionPolicy;
7-
import java.lang.annotation.Target;
8-
93
import org.springframework.context.annotation.Conditional;
104

5+
import java.lang.annotation.*;
6+
117
/**
12-
* Conditional annotation to pre-check if an extension should be picked for autoconfiguration.
13-
*
8+
* Conditional annotation to pre-check if an extension should be picked for autoconfiguration.
9+
* <p>
1410
* You can define the major Wicket version on which the extension
1511
* should or should not be executed.
16-
*
12+
*
1713
* @author Marc Giffing
1814
*/
19-
@Target({ ElementType.TYPE, ElementType.METHOD })
15+
@Target({ElementType.TYPE, ElementType.METHOD})
2016
@Retention(RetentionPolicy.RUNTIME)
2117
@Documented
2218
@Conditional(WicketSettingsCondition.class)
2319
public @interface ConditionalOnWicket {
24-
25-
/**
26-
* @return The major java version to check with the current value
27-
*/
28-
int value();
29-
30-
/**
31-
* @return Defines how the given major version should be checked with the current version
32-
*/
33-
Range range() default Range.EQUALS_OR_HIGHER;
34-
35-
36-
37-
38-
enum Range {
39-
/**
40-
* The Wicket major version equals the
41-
*/
42-
EQUALS,
43-
/**
44-
* The Wicket major version equals or is newer
45-
*/
46-
EQUALS_OR_HIGHER,
47-
48-
/**
49-
* The Wicket major version equals or is lower
50-
*/
51-
EQUALS_OR_LOWER,
52-
53-
}
20+
21+
/**
22+
* @return The major java version to check with the current value
23+
*/
24+
int value();
25+
26+
/**
27+
* @return Defines how the given major version should be checked with the current version
28+
*/
29+
Range range() default Range.EQUALS_OR_HIGHER;
30+
31+
32+
enum Range {
33+
/**
34+
* The Wicket major version equals the
35+
*/
36+
EQUALS,
37+
/**
38+
* The Wicket major version equals or is newer
39+
*/
40+
EQUALS_OR_HIGHER,
41+
42+
/**
43+
* The Wicket major version equals or is lower
44+
*/
45+
EQUALS_OR_LOWER,
46+
47+
}
5448
}
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,68 @@
11
package com.giffing.wicket.spring.boot.context.condition;
22

3-
import java.util.Map;
4-
3+
import com.giffing.wicket.spring.boot.context.condition.ConditionalOnWicket.Range;
54
import org.apache.wicket.settings.FrameworkSettings;
65
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
76
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
87
import org.springframework.context.annotation.ConditionContext;
98
import org.springframework.core.type.AnnotatedTypeMetadata;
9+
import org.springframework.util.StringUtils;
1010

11-
import com.giffing.wicket.spring.boot.context.condition.ConditionalOnWicket.Range;
11+
import java.util.Map;
1212

1313
/**
1414
* Retrieves the current major Wicket Version from the classpath and matches it against
1515
* the given conditional value in the {@link ConditionalOnWicket} annotation.
16-
*
17-
* @author Marc Giffing
1816
*
17+
* @author Marc Giffing
1918
*/
2019
public class WicketSettingsCondition extends SpringBootCondition {
2120

22-
@Override
23-
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
24-
String implVersion = null;
25-
String wicketVersion = retrieveWicketVersion(implVersion);
26-
27-
Map<String, Object> attributes = metadata
28-
.getAnnotationAttributes(ConditionalOnWicket.class.getName());
29-
Range range = (Range) attributes.get("range");
30-
int expectedVersion = (int) attributes.get("value");
31-
String[] splittedWicketVersion = wicketVersion.split("\\.");
32-
int majorWicketVersion = Integer.valueOf(splittedWicketVersion[0]);
33-
return getMatchOutcome(range, majorWicketVersion, expectedVersion);
34-
}
21+
@Override
22+
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
23+
String wicketVersion = retrieveWicketVersion();
24+
25+
Map<String, Object> attributes = metadata
26+
.getAnnotationAttributes(ConditionalOnWicket.class.getName());
27+
Range range = (Range) attributes.get("range");
28+
int expectedVersion = (int) attributes.get("value");
29+
String[] splittedWicketVersion = wicketVersion.split("\\.");
30+
int majorWicketVersion = Integer.parseInt(splittedWicketVersion[0]);
31+
return getMatchOutcome(range, majorWicketVersion, expectedVersion);
32+
}
33+
34+
protected ConditionOutcome getMatchOutcome(Range range, int runningVersion,
35+
int expectedVersion) {
36+
boolean match = matches(range, expectedVersion, runningVersion);
37+
return new ConditionOutcome(match, getMessage(match, range, runningVersion, expectedVersion));
38+
}
39+
40+
private boolean matches(Range range, int expectedVersion, int runningVersion) {
41+
return switch (range) {
42+
case EQUALS -> runningVersion == expectedVersion;
43+
case EQUALS_OR_LOWER -> runningVersion <= expectedVersion;
44+
case EQUALS_OR_HIGHER -> runningVersion >= expectedVersion;
45+
};
46+
}
47+
48+
private String getMessage(boolean matches, Range range, int runningVersion,
49+
int expectedVersion) {
50+
if (matches) {
51+
return "Wicket version matches current: " + runningVersion + " " + range + " expected: " + expectedVersion;
52+
} else {
53+
return "Wicket version does not match current: " + runningVersion + " " + range + " expected: " + expectedVersion;
54+
}
55+
}
3556

36-
protected ConditionOutcome getMatchOutcome(Range range, int runningVersion,
37-
int expectedVersion) {
38-
boolean match = matches(range, expectedVersion, runningVersion);
39-
return new ConditionOutcome(match, getMessage(match, range, runningVersion, expectedVersion));
40-
}
57+
private String retrieveWicketVersion() {
4158

42-
private boolean matches(Range range, int expectedVersion, int runningVersion) {
43-
switch(range){
44-
case EQUALS:
45-
return runningVersion == expectedVersion;
46-
case EQUALS_OR_LOWER:
47-
return runningVersion <= expectedVersion;
48-
case EQUALS_OR_HIGHER:
49-
return runningVersion >= expectedVersion;
50-
default:
51-
return false;
52-
53-
}
54-
}
59+
String implVersion = null;
60+
var pkg = FrameworkSettings.class.getPackage();
61+
if (pkg != null) {
62+
implVersion = pkg.getImplementationVersion();
63+
}
64+
return StringUtils.hasLength(implVersion) ? implVersion : "0";
65+
}
5566

56-
private String getMessage(boolean matches, Range range, int runningVersion,
57-
int expectedVersion) {
58-
if(matches){
59-
return "Wicket version matches current: " + runningVersion + " " + range + " expected: " + expectedVersion;
60-
}else {
61-
return "Wicket version does not match current: " + runningVersion + " " + range + " expected: " + expectedVersion;
62-
}
63-
}
64-
65-
private String retrieveWicketVersion(String implVersion) {
66-
67-
Package pkg = FrameworkSettings.class.getPackage();
68-
if (pkg != null)
69-
{
70-
implVersion = pkg.getImplementationVersion();
71-
}
72-
String wicketVersion = isEmpty(implVersion) ? "0" : implVersion;
73-
return wicketVersion;
74-
}
75-
76-
private boolean isEmpty(String stringToCheck){
77-
if(stringToCheck == null || stringToCheck.length() == 0){
78-
return true;
79-
}
80-
return false;
81-
}
8267

8368
}

wicket-spring-boot-context/src/main/java/com/giffing/wicket/spring/boot/context/exceptions/WicketSpringBootException.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,32 @@
22

33
/**
44
* General extension from which all exception should extend
5-
*
6-
* @author Marc Giffing
75
*
6+
* @author Marc Giffing
87
*/
9-
public class WicketSpringBootException extends RuntimeException{
8+
public class WicketSpringBootException extends RuntimeException {
109

11-
public WicketSpringBootException() {
12-
super();
13-
}
10+
public WicketSpringBootException() {
11+
super();
12+
}
1413

15-
public WicketSpringBootException(String message, Throwable cause, boolean enableSuppression,
16-
boolean writableStackTrace) {
17-
super(message, cause, enableSuppression, writableStackTrace);
18-
}
14+
public WicketSpringBootException(String message,
15+
Throwable cause,
16+
boolean enableSuppression,
17+
boolean writableStackTrace) {
18+
super(message, cause, enableSuppression, writableStackTrace);
19+
}
1920

20-
public WicketSpringBootException(String message, Throwable cause) {
21-
super(message, cause);
22-
}
21+
public WicketSpringBootException(String message, Throwable cause) {
22+
super(message, cause);
23+
}
2324

24-
public WicketSpringBootException(String message) {
25-
super(message);
26-
}
25+
public WicketSpringBootException(String message) {
26+
super(message);
27+
}
2728

28-
public WicketSpringBootException(Throwable cause) {
29-
super(cause);
30-
}
29+
public WicketSpringBootException(Throwable cause) {
30+
super(cause);
31+
}
3132

3233
}

wicket-spring-boot-context/src/main/java/com/giffing/wicket/spring/boot/context/exceptions/extensions/ExtensionMisconfigurationException.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44

55
/**
66
* This exception should be thrown if a extension misconfiguration is detected.
7-
*
7+
* <p>
88
* It can e.g. thrown if you detect an extension which configures the same aspect
9-
* like two serializers
10-
*
11-
* @author Marc Giffing
9+
* as two serializers
1210
*
11+
* @author Marc Giffing
1312
*/
1413
public class ExtensionMisconfigurationException extends WicketSpringBootException {
1514

16-
public ExtensionMisconfigurationException(String message) {
17-
super(message);
18-
}
15+
public ExtensionMisconfigurationException(String message) {
16+
super(message);
17+
}
1918

2019
}

wicket-spring-boot-context/src/main/java/com/giffing/wicket/spring/boot/context/extensions/ApplicationInitExtension.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,26 @@
1212
import org.springframework.stereotype.Component;
1313

1414
/**
15-
* To be independent from Springs annotation this annotation was introduced
15+
* To be independent of Springs annotation this annotation was introduced
1616
* which is a replacement for the {@link Component} annotation.
17-
*
18-
* In future you may introduce different configuration options.
19-
*
20-
* @author Marc Giffing
17+
* <p>
18+
* In the future, you may introduce different configuration options.
2119
*
20+
* @author Marc Giffing
2221
*/
2322
@Configuration
24-
@Target({ ElementType.TYPE })
23+
@Target({ElementType.TYPE})
2524
@Retention(RetentionPolicy.RUNTIME)
2625
@Documented
2726
@Inherited
2827
@Order(ApplicationInitExtension.DEFAULT_PRECEDENCE)
2928
public @interface ApplicationInitExtension {
3029

31-
int HIGHEST_PRECEDENCE = Integer.MIN_VALUE;
32-
33-
int DEFAULT_PRECEDENCE = Integer.MAX_VALUE / 2;
30+
int HIGHEST_PRECEDENCE = Integer.MIN_VALUE;
31+
32+
int DEFAULT_PRECEDENCE = Integer.MAX_VALUE / 2;
3433

35-
int LOWEST_PRECEDENCE = Integer.MAX_VALUE;
34+
int LOWEST_PRECEDENCE = Integer.MAX_VALUE;
3635

37-
String value() default "";
36+
String value() default "";
3837
}

wicket-spring-boot-context/src/main/java/com/giffing/wicket/spring/boot/context/extensions/WicketApplicationInitConfiguration.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@
77
* class. An extension class should implement this interface. All classes implementing
88
* this interface are injected in Wickets starter WicketBootWebApplication class as a list and on
99
* each implementation the init method is called with the current {@link WebApplication}.
10-
*
10+
* <p>
1111
* Every Spring Bean regardless to the package location which implements this interface
1212
* will be considered as an extension. This means that you can write your own extension
1313
* in a different project. You only have to ensure that the class will picked up by Springs
1414
* component scan (or other bean configuration possibilities.
15-
*
16-
* @author Marc Giffing
1715
*
16+
* @author Marc Giffing
1817
*/
1918
public interface WicketApplicationInitConfiguration {
2019

21-
/**
22-
* With the given {@link WebApplication} the
23-
* {@link WicketApplicationInitConfiguration}s can modify/extend the init()
24-
* method of the {@link WebApplication}.
25-
*
26-
* @param webApplication
27-
* the current {@link WebApplication}
28-
*/
29-
void init(WebApplication webApplication);
20+
/**
21+
* With the given {@link WebApplication} the
22+
* {@link WicketApplicationInitConfiguration}s can modify/extend the init()
23+
* method of the {@link WebApplication}.
24+
*
25+
* @param webApplication the current {@link WebApplication}
26+
*/
27+
void init(WebApplication webApplication);
3028
}

0 commit comments

Comments
 (0)