Skip to content

Commit

Permalink
Merge pull request #352 from InseeFr/feature/jdk-8
Browse files Browse the repository at this point in the history
Feature/jdk 8
  • Loading branch information
NicoLaval authored Jul 26, 2024
2 parents 0d23da9 + 37a13f5 commit 9874d77
Show file tree
Hide file tree
Showing 136 changed files with 4,745 additions and 2,231 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 8
distribution: "adopt"
- uses: s4u/[email protected]
with:
Expand All @@ -58,7 +58,7 @@ jobs:
"password": "${{ secrets.GH_PACKAGES_PASSWORD }}"
}]
- name: Test
run: mvn package
run: mvn package -DskipTests
test-sonar-package:
name: Run Trevas tests with coverage & sonar checks
# Trevas main repo commit branch or merged PR
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 8
distribution: "adopt"
- uses: s4u/[email protected]
with:
Expand All @@ -154,7 +154,7 @@ jobs:
"password": "${{ secrets.GH_PACKAGES_PASSWORD }}"
}]
- name: Publish package
run: mvn --batch-mode deploy
run: mvn --batch-mode deploy -DskipTests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.defaultLogLevel='warn'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ If you want to contribute, see this [guide](docs/CONTRIBUTING.md).

## Requirements

Open JDK 11.0.4 + is required.
Open JDK 8+ is required.
18 changes: 8 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</distributionManagement>

<properties>
<jdk.version>11</jdk.version>
<jdk.version>1.8</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jacoco.version>0.8.7</jacoco.version>
<sonar.coverage.jacoco.xmlReportPaths>
Expand All @@ -80,13 +80,13 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.0</version>
<version>5.11.0-M2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<version>3.26.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -109,7 +109,7 @@
<configuration>
<rules>
<requireJavaVersion>
<version>11.0.4</version>
<version>1.8</version>
</requireJavaVersion>
<requireMavenVersion>
<version>3.3.9</version>
Expand Down Expand Up @@ -176,10 +176,8 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.13.0</version>
<configuration>
<release>${jdk.version}</release>
<testRelease>${jdk.version}</testRelease>
<target>${jdk.version}</target>
<source>${jdk.version}</source>
</configuration>
Expand Down Expand Up @@ -209,17 +207,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>4.0.0-M15</version>
<version>4.0.0-M16</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.6.0</version>
<version>3.6.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.7.0</version>
<version>3.8.0</version>
<configuration>
<source>8</source>
<detectJavaApiLink>false</detectJavaApiLink>
Expand Down
9 changes: 5 additions & 4 deletions vtl-csv/src/main/java/fr/insee/vtl/csv/CSVDataset.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.insee.vtl.csv;

import fr.insee.vtl.model.Dataset;
import fr.insee.vtl.model.utils.Java8Helpers;
import org.supercsv.cellprocessor.Optional;
import org.supercsv.cellprocessor.ParseBool;
import org.supercsv.cellprocessor.ParseDouble;
Expand All @@ -26,8 +27,8 @@ public class CSVDataset implements Dataset {
public CSVDataset(DataStructure structure, Reader csv) throws IOException {
this.structure = structure;
this.csvReader = new CsvMapReader(csv, CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
var columns = this.csvReader.getHeader(true);
if (!this.structure.keySet().containsAll(List.of(columns))) {
String[] columns = this.csvReader.getHeader(true);
if (!this.structure.keySet().containsAll(Java8Helpers.listOf(columns))) {
throw new RuntimeException("missing columns in CSV");
}
}
Expand Down Expand Up @@ -68,8 +69,8 @@ public List<DataPoint> getDataPoints() {
if (this.data == null) {
this.data = new ArrayList<>();
try {
var header = getNameMapping();
var processors = getProcessors();
String[] header = getNameMapping();
CellProcessor[] processors = getProcessors();
Map<String, Object> datum;
while ((datum = this.csvReader.read(header, processors)) != null) {
this.data.add(new DataPoint(this.structure, datum));
Expand Down
27 changes: 24 additions & 3 deletions vtl-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
</dependency>
<!-- Because of safety mirror -->
<dependency>
<groupId>com.github.hervian</groupId>
<artifactId>safety-mirror</artifactId>
<version>4.0.1</version>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
</dependencies>
<build>
Expand All @@ -71,6 +77,21 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.34</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package fr.insee.vtl.engine;

import fr.insee.vtl.engine.exceptions.VtlRuntimeException;
import fr.insee.vtl.model.exceptions.VtlScriptException;
import org.threeten.extra.Interval;
import org.threeten.extra.PeriodDuration;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.time.*;
import java.time.temporal.*;
import java.time.temporal.ChronoUnit;

/**
* This comment explains the temporal functionality supported by Trevas, as defined in the VTL 2.0 specification.
Expand Down Expand Up @@ -188,19 +184,19 @@ public static PeriodDuration period_indicator(Interval timePeriod) {
public static Interval timeshift(Interval time, Long n) {
OffsetDateTime from = time.getStart().atOffset(ZoneOffset.UTC);
OffsetDateTime to = time.getEnd().atOffset(ZoneOffset.UTC);
var dur = PeriodDuration.between(from, to)
PeriodDuration dur = PeriodDuration.between(from, to)
.multipliedBy(n.intValue());
return Interval.of(from.plus(dur.getPeriod()).toInstant(), to.plus(dur.getPeriod()).toInstant());
}

public static ZonedDateTime at_zone(Instant op, String zone) {
var zid = ZoneId.of(zone);
ZoneId zid = ZoneId.of(zone);
return op.atZone(zid);
}


private static Interval truncate_time(Interval op, ChronoUnit unit, ZoneId zone) {
var start = truncate_time(op.getStart(), unit, zone);
Instant start = truncate_time(op.getStart(), unit, zone);
return Interval.of(start, unit.getDuration());
}

Expand All @@ -213,7 +209,7 @@ public static Interval truncate_time(Interval op, String unit) {
}

private static Instant truncate_time(Instant op, ChronoUnit unit, ZoneId zone) {
var zonedOp = op.atZone(zone);
ZonedDateTime zonedOp = op.atZone(zone);
switch (unit) {
case DAYS:
return zonedOp.truncatedTo(ChronoUnit.DAYS).toInstant();
Expand Down Expand Up @@ -248,7 +244,7 @@ public static ZonedDateTime truncate_time(ZonedDateTime op, String unit) {
}

public static OffsetDateTime truncate_time(OffsetDateTime op, String unit) {
var zoned = op.toZonedDateTime();
ZonedDateTime zoned = op.toZonedDateTime();
return truncate_time(zoned.toInstant(), toChronoUnit(unit), zoned.getZone()).atOffset(op.getOffset());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.insee.vtl.engine;

import com.github.hervian.reflection.Fun;
import fr.insee.vtl.engine.utils.safetymirror.Fun;
import fr.insee.vtl.model.utils.Java8Helpers;
import fr.insee.vtl.engine.visitors.expression.*;
import fr.insee.vtl.engine.visitors.expression.functions.ComparisonFunctionsVisitor;
import fr.insee.vtl.engine.visitors.expression.functions.DistanceFunctionsVisitor;
Expand All @@ -11,12 +12,11 @@

import java.lang.reflect.Method;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.util.Set;

public class VtlNativeMethods {

public static final Set<Method> NATIVE_METHODS = Set.of(
public static final Set<Method> NATIVE_METHODS = Java8Helpers.setOf(
// NumericFunctionsVisitor
Fun.toMethod(NumericFunctionsVisitor::ceil),
Fun.toMethod(NumericFunctionsVisitor::floor),
Expand Down
59 changes: 14 additions & 45 deletions vtl-engine/src/main/java/fr/insee/vtl/engine/VtlScriptEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,24 @@

import fr.insee.vtl.engine.exceptions.VtlRuntimeException;
import fr.insee.vtl.engine.exceptions.VtlSyntaxException;
import fr.insee.vtl.model.utils.Java8Helpers;
import fr.insee.vtl.engine.visitors.AssignmentVisitor;
import fr.insee.vtl.model.FunctionProvider;
import fr.insee.vtl.model.Positioned;
import fr.insee.vtl.model.ProcessingEngine;
import fr.insee.vtl.model.ProcessingEngineFactory;
import fr.insee.vtl.model.VtlMethod;
import fr.insee.vtl.model.*;
import fr.insee.vtl.model.exceptions.VtlScriptException;
import fr.insee.vtl.parser.VtlLexer;
import fr.insee.vtl.parser.VtlParser;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CodePointCharStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;

import javax.script.AbstractScriptEngine;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
import javax.script.*;
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.StringJoiner;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -113,7 +84,7 @@ public static Positioned fromTokens(Token from, Token to) {
if (to == null) {
to = from;
}
var position = new Positioned.Position(
Positioned.Position position = new Positioned.Position(
from.getLine() - 1,
to.getLine() - 1,
from.getCharPositionInLine(),
Expand Down Expand Up @@ -201,12 +172,10 @@ private String getProcessingEngineName() {
*/
public ProcessingEngine getProcessingEngine() {
String name = getProcessingEngineName();
Optional<ProcessingEngineFactory> factory = ServiceLoader.load(ProcessingEngineFactory.class)
.stream()
.map(ServiceLoader.Provider::get)
Optional<ProcessingEngineFactory> factory = Java8Helpers.streamIterator(ServiceLoader.load(ProcessingEngineFactory.class).iterator())
.filter(f -> f.getName().equals(name))
.findFirst();
return factory.orElseThrow().getProcessingEngine(this);
return factory.orElseThrow(() -> new NoSuchElementException("No value present")).getProcessingEngine(this);
}

/**
Expand All @@ -231,7 +200,7 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int
if (offendingSymbol instanceof Token) {
errors.add(new VtlSyntaxException(msg, fromToken((Token) offendingSymbol)));
} else {
var pos = new Positioned.Position(startLine, startLine, startColumn, startColumn + 1);
Positioned.Position pos = new Positioned.Position(startLine, startLine, startColumn, startColumn + 1);
errors.add(new VtlScriptException(msg, () -> pos));
}
}
Expand All @@ -248,10 +217,10 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int

// Note that we need to call this method to trigger the
// error listener.
var start = parser.start();
VtlParser.StartContext start = parser.start();

if (!errors.isEmpty()) {
var first = errors.removeFirst();
VtlScriptException first = errors.removeFirst();
for (VtlScriptException suppressed : errors) {
first.addSuppressed(suppressed);
}
Expand Down Expand Up @@ -322,14 +291,14 @@ public ScriptEngineFactory getFactory() {
}

public VtlMethod findMethod(String name, Collection<Class> types) throws NoSuchMethodException {
Set<Method> customMethods = methodCache == null ? Set.of()
Set<Method> customMethods = methodCache == null ? Java8Helpers.setOf()
: new HashSet<>(methodCache.values());
Set<Method> methods = Stream.concat(NATIVE_METHODS.stream(), customMethods.stream())
.collect(Collectors.toSet());

List<Method> candidates = methods.stream()
.filter(method -> method.getName().equals(name))
.filter(method -> matchParameters(method, types.toArray(Class[]::new)))
.filter(method -> matchParameters(method, types.toArray(new Class[0])))
.collect(Collectors.toList());
if (candidates.size() == 1) {
return new VtlMethod(candidates.get(0));
Expand All @@ -349,7 +318,7 @@ public VtlMethod findGlobalMethod(String name, Collection<Class> types) throws N

List<Method> candidates = methods.stream()
.filter(method -> method.getName().equals(name))
.filter(method -> matchParameters(method, types.toArray(Class[]::new)))
.filter(method -> matchParameters(method, types.toArray(new Class[0])))
.collect(Collectors.toList());

if (candidates.size() == 0) {
Expand Down
Loading

0 comments on commit 9874d77

Please sign in to comment.