Commit 8f91e144 authored by Daniel Bluhm's avatar Daniel Bluhm

Fix running with Java versions > 11 failing tests

DataElementProcessor tests loosened to not consider warnings a failure
condition. Removed LoggingDataElementProcessor in favor of just having a
standard logger during testing; leave it up to tester to determine if
warnings are serious or not.
Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 2f835787
......@@ -103,9 +103,9 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.cosium.logging</groupId>
<artifactId>annotation-processor-logger</artifactId>
<version>1.0</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
</dependencies>
......
......@@ -19,6 +19,8 @@ import javax.annotation.processing.Processor;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import org.eclipse.ice.dev.annotations.processors.DataElementProcessor;
import com.google.testing.compile.Compilation;
import static com.google.testing.compile.Compiler.*;
......@@ -85,7 +87,7 @@ public class DataElementAnnotationTestHelper {
Compilation compilation = javac()
.withProcessors(
getLombokAnnotationProcessor(),
new LoggingDataElementProcessor()
new DataElementProcessor()
).compile(sources);
if (showDiagnostics) {
printDiagnostics(compilation);
......
......@@ -13,9 +13,14 @@ package org.eclipse.ice.tests.dev.annotations.processors;
import static com.google.testing.compile.CompilationSubject.*;
import java.util.Locale;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.testing.compile.Compilation;
......@@ -56,6 +61,11 @@ class DataElementProcessorTest {
*/
private static final String IMPLEMENTATION = "TestImplementation";
/**
* Logger.
*/
private static final Logger logger = LoggerFactory.getLogger(DataElementProcessorTest.class);
/**
* Enumeration of inputs used in testing.
* @author Daniel Bluhm
......@@ -137,6 +147,17 @@ class DataElementProcessorTest {
return PARENT + this.filename;
}
}
/**
* Assert that the compilation succeeded and log any warnings.
* @param compilation to check.
*/
private static void assertSucceededAndLogWarnings(Compilation compilation) {
assertThat(compilation).succeeded();
for (Diagnostic<?> warning : compilation.warnings()) {
logger.warn(warning.getMessage(Locale.ENGLISH));
}
}
/**
* Assert that the interface generated in this compilation matches the given
......@@ -224,7 +245,7 @@ class DataElementProcessorTest {
@Test
void testNoDataFieldsSucceeds() {
Compilation compilation = helper.compile(Inputs.NO_DATAFIELDS.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertDefaultsPresent(compilation);
}
......@@ -234,7 +255,7 @@ class DataElementProcessorTest {
@Test
void testWithSingleDataFieldSucceeds() {
Compilation compilation = helper.compile(Inputs.SINGLE.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertDefaultsPresent(compilation);
assertInterfaceMatches(compilation, Patterns.SINGLE_INT.get());
assertImplementationMatches(compilation, Patterns.SINGLE_IMPL.get());
......@@ -246,7 +267,7 @@ class DataElementProcessorTest {
@Test
void testWithManyDataFieldsSucceeds() {
Compilation compilation = helper.compile(Inputs.MANY.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertDefaultsPresent(compilation);
assertInterfaceMatches(compilation, Patterns.MANY_INT.get());
assertImplementationMatches(compilation, Patterns.MANY_IMPL.get());
......@@ -258,7 +279,7 @@ class DataElementProcessorTest {
@Test
void testSingleNonPrimitiveDataFieldSucceeds() {
Compilation compilation = helper.compile(Inputs.SINGLE_NON_PRIMITIVE.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertDefaultsPresent(compilation);
assertInterfaceMatches(compilation, Patterns.SINGLE_NON_PRIMITIVE_INT.get());
assertImplementationMatches(compilation, Patterns.SINGLE_NON_PRIMITIVE_IMPL.get());
......@@ -270,7 +291,7 @@ class DataElementProcessorTest {
@Test
void testManyNonPrimitiveDataFieldSucceeds() {
Compilation compilation = helper.compile(Inputs.MANY_NON_PRIMITIVE.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertDefaultsPresent(compilation);
assertInterfaceMatches(compilation, Patterns.MANY_NON_PRIMITIVE_INT.get());
assertImplementationMatches(compilation, Patterns.MANY_NON_PRIMITIVE_IMPL.get());
......@@ -303,7 +324,7 @@ class DataElementProcessorTest {
@Test
void testDocStringsPreserved() {
Compilation compilation = helper.compile(Inputs.SINGLE.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertThat(compilation).generatedSourceFile(IMPLEMENTATION)
.contentsAsUtf8String()
.contains("* A UNIQUE STRING IN THE DOC STRING.");
......@@ -319,7 +340,7 @@ class DataElementProcessorTest {
@Test
void testAccessibilityPreserved() {
Compilation compilation = helper.compile(Inputs.ACCESSIBILITY_PRESERVED.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertImplementationMatches(compilation, Patterns.ACCESSIBILITY_PRESERVED.get());
}
......@@ -352,7 +373,7 @@ class DataElementProcessorTest {
@Test
void testDataFieldGetterOption() {
Compilation compilation = helper.compile(Inputs.DATAFIELD_GETTER.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertThat(compilation)
.generatedSourceFile(INTERFACE)
.hasSourceEquivalentTo(Patterns.DATAFIELD_GETTER_INT.get());
......@@ -364,7 +385,7 @@ class DataElementProcessorTest {
@Test
void testDataFieldSetterOption() {
Compilation compilation = helper.compile(Inputs.DATAFIELD_SETTER.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertThat(compilation)
.generatedSourceFile(INTERFACE)
.hasSourceEquivalentTo(Patterns.DATAFIELD_SETTER_INT.get());
......@@ -376,7 +397,7 @@ class DataElementProcessorTest {
@Test
void testDataFieldMatchOption() {
Compilation compilation = helper.compile(Inputs.DATAFIELD_MATCH.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertThat(compilation)
.generatedSourceFile(IMPLEMENTATION)
.contentsAsUtf8String()
......@@ -393,7 +414,7 @@ class DataElementProcessorTest {
@Test
void testDataFieldDefaultNonString() {
Compilation compilation = helper.compile(Inputs.DEFAULT_NON_STRING.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertImplementationMatches(
compilation,
Patterns.DEFAULT_NON_STRING_IMPL.get()
......@@ -406,7 +427,7 @@ class DataElementProcessorTest {
@Test
void testDataFieldDefaultString() {
Compilation compilation = helper.compile(Inputs.DEFAULT_STRING.get());
assertThat(compilation).succeededWithoutWarnings();
assertSucceededAndLogWarnings(compilation);
assertImplementationMatches(
compilation,
Patterns.DEFAULT_STRING_IMPL.get()
......
/*******************************************************************************
* Copyright (c) 2020- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Daniel Bluhm - Initial implementation
*******************************************************************************/
package org.eclipse.ice.tests.dev.annotations.processors;
import java.util.Set;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import org.eclipse.ice.dev.annotations.processors.DataElementProcessor;
import com.cosium.logging.annotation_processor.AbstractLoggingProcessor;
/**
* Wrapper around DataElementProcessor used to catch warnings that would
* normally be missed.
* @author Daniel Bluhm
*/
@SupportedAnnotationTypes({
"org.eclipse.ice.dev.annotations.DataElement",
"org.eclipse.ice.dev.annotations.DataField",
"org.eclipse.ice.dev.annotations.DataField.Default",
"org.eclipse.ice.dev.annotations.Persisted"
})
@SupportedSourceVersion(SourceVersion.RELEASE_11)
public class LoggingDataElementProcessor extends AbstractLoggingProcessor {
/**
* Wrapped processor.
*/
private DataElementProcessor wrappedProcessor = new DataElementProcessor();
@Override
public void init(final ProcessingEnvironment env) {
wrappedProcessor.init(env);
super.init(env);
}
@Override
protected boolean doProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return wrappedProcessor.process(annotations, roundEnv);
}
}
\ No newline at end of file
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all
# defined loggers, to System.err.
# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=info
# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=
# Set to true if you want the current date and time to be included in output
# messages. Default is false, and will output the number of milliseconds elapsed
# since startup.
#org.slf4j.simpleLogger.showDateTime=false
# The date and time format to be used in the output messages. The pattern
# describing the date and time format is the same that is used in
# java.text.SimpleDateFormat. If the format is not specified or is invalid, the
# default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
# Set to true if you want to output the current thread name.
# Defaults to true.
#org.slf4j.simpleLogger.showThreadName=true
# Set to true if you want the Logger instance name to be included in output
# messages. Defaults to true.
#org.slf4j.simpleLogger.showLogName=true
# Set to true if you want the last component of the name to be included in
# output messages. Defaults to false.
#org.slf4j.simpleLogger.showShortLogName=false
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment