Skip to content

Commit ea9ad0d

Browse files
committed
Updated dependencies/Fixed build for newer Java versions, dropped Java 7 support
1 parent 9c6661c commit ea9ad0d

File tree

8 files changed

+88
-106
lines changed

8 files changed

+88
-106
lines changed

.github/workflows/default.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
runs-on: ${{ matrix.os }}
1313
strategy:
1414
matrix:
15-
os: [ubuntu-latest,macos-latest]
16-
java: [ 7, 7.0.181, 8, 8.0.192, 9.0.x, 10, 11.0.x, 11.0.3, 12 ]
15+
os: [ ubuntu-latest,macos-latest ]
16+
java: [ 8.0.x, 9.0.x, 11.0.x, 12.0.x, 13.0.x, 14.0.x, 15.0.x, 16.0.x, 17.0.x, 18.0.x ]
1717

1818
steps:
1919
- uses: actions/checkout@v1

.github/workflows/jacoco.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: ./mvnw verify jacoco:report-aggregate -B -q
3636

3737
- name: Upload coverage to Codecov
38-
uses: codecov/codecov-action@v1.0.2
38+
uses: codecov/codecov-action@v2
3939
with:
4040
token: ${{secrets.CODECOV_TOKEN}}
41-
file: target/site/jacoco-aggregate/jacoco.xml
41+
files: target/site/jacoco-aggregate/jacoco.xml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Additionally it will generate a service locator for you.
1616
Annotation processor that
1717
- provides support for generating service locator file in _/META-INF/services/<Full qualified spi interface name>_
1818
- provides support for generating service locator class for accessing the SPI implementations
19+
- compatible with Java >= 8 (Java 7 support up to version 0.8.2)
1920

2021
# How does it work?
2122

pom.xml

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,28 @@
7676
<project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
7777
<encoding>UTF-8</encoding>
7878

79-
<java.version>1.7</java.version>
79+
<java.version>1.8</java.version>
8080

81-
<java.compile.source.version>1.7</java.compile.source.version>
82-
<java.compile.target.version>1.7</java.compile.target.version>
81+
<java.compile.source.version>${java.version}</java.compile.source.version>
82+
<java.compile.target.version>${java.version}</java.compile.target.version>
8383

8484

85-
<cute.version>0.9.0</cute.version>
86-
<aptk.version>0.15.1</aptk.version>
85+
<cute.version>0.12.0</cute.version>
86+
<aptk.version>0.20.0</aptk.version>
8787

8888
<!-- versions of test dependencies -->
89-
<junit.version>4.12</junit.version>
89+
<junit.version>4.13.2</junit.version>
9090
<hamcrest.version>2.2</hamcrest.version>
91-
<mockito.version>2.28.2</mockito.version>
92-
<lombok.version>1.18.4</lombok.version>
93-
91+
<mockito.version>4.5.1</mockito.version>
9492

9593
<!-- plugin versions -->
96-
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
97-
<maven-assembly-plugin.version>2.4</maven-assembly-plugin.version>
98-
<maven-bundle-plugin.version>4.2.1</maven-bundle-plugin.version>
99-
<maven-failsafe-plugin.version>2.18.1</maven-failsafe-plugin.version>
100-
<maven-jacoco-plugin.version>0.8.2</maven-jacoco-plugin.version>
101-
<maven-processor-plugin.version>2.2.4</maven-processor-plugin.version>
102-
<maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
94+
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
95+
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
96+
<maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
97+
<maven-jacoco-plugin.version>0.8.8</maven-jacoco-plugin.version>
98+
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
10399

104-
<maven-javadoc-plugin.version>3.3.1</maven-javadoc-plugin.version>
100+
<maven-javadoc-plugin.version>3.4.0</maven-javadoc-plugin.version>
105101

106102

107103
</properties>
@@ -386,14 +382,14 @@
386382

387383
<dependency>
388384
<groupId>io.toolisticon.aptk</groupId>
389-
<artifactId>tools</artifactId>
385+
<artifactId>aptk-tools</artifactId>
390386
<version>${aptk.version}</version>
391387
</dependency>
392388

393389
<!-- processors apis -->
394390
<dependency>
395391
<groupId>io.toolisticon.aptk</groupId>
396-
<artifactId>annotationwrapper-api</artifactId>
392+
<artifactId>aptk-annotationwrapper-api</artifactId>
397393
<version>${aptk.version}</version>
398394
<scope>provided</scope>
399395
</dependency>

processor/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<dependency>
2020
<groupId>io.toolisticon.aptk</groupId>
21-
<artifactId>tools</artifactId>
21+
<artifactId>aptk-tools</artifactId>
2222
</dependency>
2323

2424
<dependency>
@@ -28,7 +28,7 @@
2828

2929
<dependency>
3030
<groupId>io.toolisticon.aptk</groupId>
31-
<artifactId>annotationwrapper-api</artifactId>
31+
<artifactId>aptk-annotationwrapper-api</artifactId>
3232
</dependency>
3333

3434
<dependency>
@@ -110,7 +110,7 @@
110110
<annotationProcessorPaths>
111111
<path>
112112
<groupId>io.toolisticon.aptk</groupId>
113-
<artifactId>annotationwrapper-processor</artifactId>
113+
<artifactId>aptk-annotationwrapper-processor</artifactId>
114114
<version>${aptk.version}</version>
115115
</path>
116116
</annotationProcessorPaths>

processor/src/main/java/io/toolisticon/spiap/processor/ServiceProcessor.java

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package io.toolisticon.spiap.processor;
22

33
import io.toolisticon.aptk.tools.AbstractAnnotationProcessor;
4-
import io.toolisticon.aptk.tools.AnnotationUtils;
54
import io.toolisticon.aptk.tools.ElementUtils;
65
import io.toolisticon.aptk.tools.FilerUtils;
76
import io.toolisticon.aptk.tools.MessagerUtils;
8-
import io.toolisticon.aptk.tools.ProcessingEnvironmentUtils;
7+
import io.toolisticon.aptk.tools.TypeMirrorWrapper;
98
import io.toolisticon.aptk.tools.TypeUtils;
109
import io.toolisticon.aptk.tools.generators.SimpleResourceWriter;
10+
import io.toolisticon.aptk.tools.wrapper.ElementWrapper;
11+
import io.toolisticon.aptk.tools.wrapper.TypeElementWrapper;
1112
import io.toolisticon.spiap.api.OutOfService;
1213
import io.toolisticon.spiap.api.Service;
1314
import io.toolisticon.spiap.api.Services;
1415

1516
import javax.annotation.processing.RoundEnvironment;
1617
import javax.lang.model.element.Element;
1718
import javax.lang.model.element.TypeElement;
18-
import javax.lang.model.type.TypeMirror;
1919
import javax.tools.StandardLocation;
2020
import java.io.IOException;
2121
import java.io.StringWriter;
@@ -28,15 +28,13 @@
2828
/**
2929
* Annotation Processor for {@link Service} and {@link Services}.
3030
* Creates the service descriptor file in "/META-INF/services/fqnOfSpi".
31-
* Additionally it creates a property file containing all additional metadata used by the ServiceLocator (like order, id and description)
31+
* Additionally, it creates a property file containing all additional metadata used by the ServiceLocator (like order, id and description)
3232
* to get rid of the api library as run time dependency.
3333
*/
3434
public class ServiceProcessor extends AbstractAnnotationProcessor {
3535

3636
private final static Set<String> SUPPORTED_ANNOTATIONS = createSupportedAnnotationSet(Services.class, Service.class);
3737

38-
private final Map<String, SimpleResourceWriter> spiResourceFilePool = new HashMap<String, SimpleResourceWriter>();
39-
4038
private final ServiceImplMap serviceImplHashMap = new ServiceImplMap();
4139

4240
/**
@@ -46,18 +44,14 @@ protected static class ServiceImplMap extends HashMap<String, Set<String>> {
4644

4745
/**
4846
* Convenience method to add a value.
49-
* Creates a Set if no entry for passedkey can be found.
47+
* Creates a Set if no entry for passed key can be found.
5048
*
5149
* @param key the key to look for
5250
* @param value the value to store in keys set
5351
* @return the keys set
5452
*/
5553
public Set<String> put(String key, String value) {
56-
Set<String> set = this.get(key);
57-
if (set == null) {
58-
set = new HashSet<String>();
59-
this.put(key, set);
60-
}
54+
Set<String> set = this.computeIfAbsent(key, k -> new HashSet<>());
6155
set.add(value);
6256
return set;
6357
}
@@ -73,7 +67,7 @@ public Set<String> getSupportedAnnotationTypes() {
7367
public boolean processAnnotations(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
7468

7569
if (!roundEnv.processingOver()) {
76-
processAnnotationsInternally(annotations, roundEnv);
70+
processAnnotationsInternally(roundEnv);
7771
} else {
7872
writeConfigurationFiles();
7973
}
@@ -82,7 +76,7 @@ public boolean processAnnotations(Set<? extends TypeElement> annotations, RoundE
8276

8377
}
8478

85-
private void processAnnotationsInternally(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
79+
private void processAnnotationsInternally(RoundEnvironment roundEnv) {
8680

8781
// process Services annotation
8882
for (Element element : roundEnv.getElementsAnnotatedWith(Services.class)) {
@@ -93,7 +87,7 @@ private void processAnnotationsInternally(Set<? extends TypeElement> annotations
9387
}
9488

9589
// read annotation
96-
ServicesWrapper servicesAnnotationWrapper = ServicesWrapper.wrapAnnotationOfElement(element);
90+
ServicesWrapper servicesAnnotationWrapper = ServicesWrapper.wrap(element);
9791

9892
for (ServiceWrapper serviceWrapper : servicesAnnotationWrapper.value()) {
9993
processAnnotation(serviceWrapper, element);
@@ -112,7 +106,7 @@ private void processAnnotationsInternally(Set<? extends TypeElement> annotations
112106
}
113107

114108
// read annotation
115-
ServiceWrapper serviceAnnotationWrapper = ServiceWrapper.wrapAnnotationOfElement(element);
109+
ServiceWrapper serviceAnnotationWrapper = ServiceWrapper.wrap(element);
116110

117111
processAnnotation(serviceAnnotationWrapper, element);
118112

@@ -141,31 +135,31 @@ private void processAnnotation(ServiceWrapper serviceAnnotationWrapper, Element
141135

142136
// Now create the service locator
143137

144-
TypeElement typeElement = ElementUtils.CastElement.castClass(annotatedElement);
138+
TypeElementWrapper typeElement = TypeElementWrapper.wrap((TypeElement) annotatedElement);
145139

146140
if (serviceAnnotationWrapper != null) {
147141

148-
Set<String> spiInterfaces = new HashSet<String>();
142+
Set<String> spiInterfaces = new HashSet<>();
149143
String spiAttributeTypes = serviceAnnotationWrapper.valueAsFqn();
150144
if (spiAttributeTypes != null) {
151145
spiInterfaces.add(spiAttributeTypes);
152146
}
153147

154148
for (String fqTypeName : spiInterfaces) {
155149

156-
TypeMirror typeMirror = TypeUtils.TypeRetrieval.getTypeMirror(fqTypeName);
157-
TypeElement typeMirrorTypeElement = (TypeElement) ProcessingEnvironmentUtils.getTypes().asElement(typeMirror);
150+
TypeMirrorWrapper typeMirror = TypeMirrorWrapper.wrap(fqTypeName);
151+
TypeElementWrapper typeMirrorTypeElement = typeMirror.getTypeElement().get();
158152

159153
//check if type is interface
160-
if (!ElementUtils.CheckKindOfElement.isInterface(typeMirrorTypeElement)) {
161-
MessagerUtils.error(annotatedElement, ServiceProcessorMessages.ERROR_VALUE_ATTRIBUTE_MUST_ONLY_CONTAIN_INTERFACES, typeMirrorTypeElement.getQualifiedName().toString());
154+
if (!typeMirrorTypeElement.isInterface()) {
155+
MessagerUtils.error(annotatedElement, ServiceProcessorMessages.ERROR_VALUE_ATTRIBUTE_MUST_ONLY_CONTAIN_INTERFACES, typeMirrorTypeElement.getQualifiedName());
162156
break;
163157
}
164158

165159
// check if annotatedElement is assignable to spi interface == implements the spi interface
166-
if (!TypeUtils.TypeComparison.isAssignableTo(typeElement, typeMirror)) {
160+
if (!TypeUtils.TypeComparison.isAssignableTo(typeElement.unwrap(), typeMirror.unwrap())) {
167161

168-
MessagerUtils.error(annotatedElement, ServiceProcessorMessages.ERROR_ANNOTATED_CLASS_MUST_IMPLEMENT_CONFIGURED_INTERFACES, typeMirrorTypeElement.getQualifiedName().toString());
162+
MessagerUtils.error(annotatedElement, ServiceProcessorMessages.ERROR_ANNOTATED_CLASS_MUST_IMPLEMENT_CONFIGURED_INTERFACES, typeMirrorTypeElement.getQualifiedName());
169163
break;
170164

171165
}
@@ -174,7 +168,7 @@ private void processAnnotation(ServiceWrapper serviceAnnotationWrapper, Element
174168
writePropertiesFile(typeElement, serviceAnnotationWrapper);
175169

176170
// put service provider implementations in map by using the SPI fqn as key
177-
serviceImplHashMap.put(fqTypeName, typeElement.getQualifiedName().toString());
171+
serviceImplHashMap.put(fqTypeName, typeElement.getQualifiedName());
178172

179173

180174
}
@@ -186,15 +180,15 @@ private void processAnnotation(ServiceWrapper serviceAnnotationWrapper, Element
186180
* This method generates the property files of configured service annotation values.
187181
* This allows us not to get rid of spiap-api dependency at runtime.
188182
*
189-
* @param annotatedTypeElement the annotated element
190-
* @param serviceAnnotationWrapper The Service annotations AnotationMirror
183+
* @param annotatedTypeElement the annotated element
184+
* @param serviceAnnotationWrapper The Service annotations AnnotationMirror
191185
*/
192-
private void writePropertiesFile(TypeElement annotatedTypeElement, ServiceWrapper serviceAnnotationWrapper) {
186+
private void writePropertiesFile(TypeElementWrapper annotatedTypeElement, ServiceWrapper serviceAnnotationWrapper) {
193187

194188

195189
String spiClassName = serviceAnnotationWrapper.valueAsFqn();
196-
;
197-
String serviceClassName = annotatedTypeElement.getQualifiedName().toString();
190+
191+
String serviceClassName = annotatedTypeElement.getQualifiedName();
198192
String fileName = "META-INF/spiap/" + spiClassName + "/" + serviceClassName + ".properties";
199193

200194
try {
@@ -209,7 +203,7 @@ private void writePropertiesFile(TypeElement annotatedTypeElement, ServiceWrappe
209203
properties.setProperty(Constants.PROPERTY_KEY_ID, !serviceAnnotationWrapper.id().isEmpty() ? serviceAnnotationWrapper.id() : serviceClassName);
210204
properties.setProperty(Constants.PROPERTY_KEY_DESCRIPTION, serviceAnnotationWrapper.description());
211205
properties.setProperty(Constants.PROPERTY_KEY_PRIORITY, "" + serviceAnnotationWrapper.priority());
212-
properties.setProperty(Constants.PROPERTY_KEY_OUT_OF_SERVICE, "" + (AnnotationUtils.getAnnotationMirror(annotatedTypeElement, OutOfService.class) != null));
206+
properties.setProperty(Constants.PROPERTY_KEY_OUT_OF_SERVICE, "" + annotatedTypeElement.getAnnotation(OutOfService.class).isPresent());
213207

214208
StringWriter writer = new StringWriter();
215209
properties.store(writer, "Property files used by the spi service locator");
@@ -221,8 +215,7 @@ private void writePropertiesFile(TypeElement annotatedTypeElement, ServiceWrappe
221215

222216

223217
} catch (IOException e) {
224-
MessagerUtils.error(annotatedTypeElement, "Wasn't able to write service provider properties file for service ${0} for spi ${1}", serviceClassName, spiClassName);
225-
return;
218+
MessagerUtils.error(annotatedTypeElement.unwrap(), "Wasn't able to write service provider properties file for service ${0} for spi ${1}", serviceClassName, spiClassName);
226219
}
227220

228221
}
@@ -244,15 +237,15 @@ private void writeConfigurationFiles() {
244237
return;
245238
}
246239

247-
Set<String> allServiceImplementations = new HashSet<String>(entry.getValue());
240+
Set<String> allServiceImplementations = new HashSet<>(entry.getValue());
248241
allServiceImplementations.addAll(existingServiceImplementations);
249242

250243
try {
251244

252245
// write service provider file by using a template
253246
SimpleResourceWriter writer = FilerUtils.createResource(StandardLocation.CLASS_OUTPUT, "", serviceProviderFile);
254247

255-
Map<String, Object> model = new HashMap<String, Object>();
248+
Map<String, Object> model = new HashMap<>();
256249
model.put("fqns", allServiceImplementations);
257250

258251
writer.writeTemplateString("!{for fqn: fqns}${fqn}\n!{/for}", model);
@@ -294,7 +287,7 @@ protected Set<String> readServiceFile(String serviceProviderFile) {
294287

295288
MessagerUtils.info(null, "Reading existing service file : ${0}", serviceProviderFile);
296289

297-
Set<String> resultSet = new HashSet<String>();
290+
Set<String> resultSet = new HashSet<>();
298291

299292
try {
300293

0 commit comments

Comments
 (0)