Skip to content

Commit

Permalink
Merge pull request #2 from MikeEdgar/1_fix_build
Browse files Browse the repository at this point in the history
[#1] Fix Travis build issue, test with JDK 8 + 11
  • Loading branch information
MikeEdgar authored Jan 26, 2020
2 parents a3eeb17 + 030b95a commit e357082
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 58 deletions.
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
language: java

jdk:
- oraclejdk8
dist: xenial

jdk:
- openjdk8
- openjdk11

script:
- mvn -B test javadoc:javadoc

after_success:
- mvn clean verify jacoco:report coveralls:report
- ./ci_coverage.sh
7 changes: 7 additions & 0 deletions ci_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

if [[ $(bc -l <<< "$(java -version 2>&1 | awk -F '\"' '/version/ {print $2}' | awk -F'.' '{print $1"."$2}') >= 11") -eq 1 ]]; then
mvn -B verify jacoco:report coveralls:report
else
echo "Not Java 11"
fi
67 changes: 31 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>io.xlate</groupId>
<artifactId>validators</artifactId>
Expand Down Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
<optional>true</optional>
</dependency>

Expand All @@ -100,9 +100,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.0.Final</version>
<version>6.1.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -149,36 +149,6 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<inherited>false</inherited>
<configuration>
<release>8</release>
</configuration>
</execution>
<!-- <execution>
<id>jdk9</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>9</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution> -->
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -335,10 +305,35 @@
</build>
</profile>
<profile>
<id>java9</id>
<id>multirelease</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<inherited>false</inherited>
<configuration>
<release>8</release>
</configuration>
</execution>
<!-- <execution> <id>module-compile</id> <goals> <goal>compile</goal> </goals> <configuration> <release>9</release> <compileSourceRoots> <compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
</compileSourceRoots> <multiReleaseOutput>true</multiReleaseOutput> </configuration> </execution> -->
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<!-- For surefire tests -->
<argLine>--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED</argLine>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.validation.ConstraintDeclarationException;
import javax.validation.ConstraintValidator;
Expand All @@ -28,22 +30,24 @@

public class DateTimeValidator implements ConstraintValidator<DateTime, CharSequence> {

private DateTime annotation;
private List<DateFormat> formats;

@Override
public void initialize(DateTime constraintAnnotation) {
annotation = constraintAnnotation;

final DateTime annotation = constraintAnnotation;
final String[] patterns = annotation.patterns();

if (patterns.length == 0) {
throw new ConstraintDeclarationException("At least one DateFormat pattern must be provided.");
}

formats = new ArrayList<>(patterns.length);

for (String pattern : patterns) {
try {
@SuppressWarnings("unused")
Object format = new SimpleDateFormat(pattern);
DateFormat format = new SimpleDateFormat(pattern);
format.setLenient(annotation.lenient());
formats.add(format);
} catch (IllegalArgumentException e) {
throw new ConstraintDeclarationException("Invalid format pattern `" + pattern + "`", e);
}
Expand All @@ -58,16 +62,15 @@ public boolean isValid(CharSequence sequence, ConstraintValidatorContext context

final String value = sequence.toString();

for (String pattern : annotation.patterns()) {
final DateFormat format = new SimpleDateFormat(pattern);

format.setLenient(annotation.lenient());
for (DateFormat format : formats) {
// DateFormat is not thread-safe, clone a local copy before use.
final DateFormat localFormat = (DateFormat) format.clone();

try {
format.parse(value);
localFormat.parse(value);
return true;
} catch (@SuppressWarnings("unused") ParseException e) {
continue;
// Value does not match the pattern, ignore and continue.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ public boolean isValid(Object target, ConstraintValidatorContext context) {
return valid;
}

DataSource getDataSource(String dataSourceLookup) {
final DataSource dataSource;
static DataSource getDataSource(String dataSourceLookup) {
final DataSource source;

try {
if (dataSourceLookup.isEmpty()) {
dataSource = InitialContext.doLookup("java:comp/DefaultDataSource");
source = InitialContext.doLookup("java:comp/DefaultDataSource");
} else {
dataSource = InitialContext.doLookup(dataSourceLookup);
source = InitialContext.doLookup(dataSourceLookup);
}
} catch (NamingException e) {
throw new ValidationException("DataSource not found", e);
}

return dataSource;
return source;
}

boolean executeQuery(ELProcessor processor, String sql, String[] parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void testGetDataSourceReturnsDefault() throws NamingException {
context.createSubcontext("java:comp");
context.bind("java:comp/DefaultDataSource", dataSource);
try {
assertEquals(dataSource, target.getDataSource(""));
assertEquals(dataSource, JdbcStatementValidator.getDataSource(""));
} finally {
context.close();
}
Expand All @@ -109,7 +109,7 @@ void testGetDataSourceReturnsNamed() throws NamingException {
String lookup = "java:comp/env/jdbc/testDataSource";
context.bind(lookup, dataSource);
try {
assertEquals(dataSource, target.getDataSource(lookup));
assertEquals(dataSource, JdbcStatementValidator.getDataSource(lookup));
} finally {
context.close();
}
Expand All @@ -130,7 +130,7 @@ void testGetDataSourceThrowsValidationExceptionCausedByNamingException() throws
ValidationException ex;
try {
ex = assertThrows(ValidationException.class, () -> {
target.getDataSource(lookup);
JdbcStatementValidator.getDataSource(lookup);
});
} finally {
context.close();
Expand Down

0 comments on commit e357082

Please sign in to comment.