Skip to content

Commit

Permalink
#570 JDK11 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Dec 29, 2018
1 parent e7ffc49 commit 8e1afd5
Show file tree
Hide file tree
Showing 64 changed files with 204 additions and 242 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ install:
- TERM=dumb ./gradlew -q assemble
matrix:
include:
- jdk: oraclejdk8
- jdk: oraclejdk11
env: PROFILE="-Dspring.profiles.active=travis -Ddbenv=PGSQL-TRAVIS -Dpgsql9.6"
dist: trusty
addons:
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ steps:
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkVersionOption: '11'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
Expand Down
21 changes: 5 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,12 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


//as pointed out by @facundofarias, we should check minimum javac version in order to avoid problems with type inference mechanism during compilation
//as pointed out by @facundofarias, we should validate minimum javac version
task validate {
//check JDK version
def javaVersion = JavaVersion.current();
if (!javaVersion.isJava8Compatible()) {
throw new GradleException("A Java JDK 8+ is required to build the project.")
}
//check build number, but only if current java version is 8
if (javaVersion == JavaVersion.VERSION_1_8) {
def currentVersion = System.getProperty("java.version")
def matcher = Pattern.compile("1(\\.\\d+){2}_(\\d+)").matcher(currentVersion)
if (!matcher.find()) {
throw new GradleException(currentVersion + " is not a recognized java version. Please report this issue.")
}
def buildNumber = Integer.parseInt(matcher.group(2))
if(buildNumber < 25) {
throw new GradleException(currentVersion + " is not a supported JDK version. Minimum version is 1.8.0b25. Please update your local JDK.")
}
def javaVersion = JavaVersion.current()
if (!javaVersion.isJava11Compatible()) {
throw new GradleException("A Java JDK 11+ is required to build the project.")
}
}

Expand Down Expand Up @@ -246,6 +234,7 @@ compileJava {
test {
useJUnitPlatform()
systemProperties = System.properties
jvmArgs("--illegal-access=warn")
testLogging {
events "failed"
exceptionFormat "full"
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
group=alfio
version=2.0-M1-SNAPSHOT

sourceCompatibility=1.8
targetCompatibility=1.8
sourceCompatibility=11
targetCompatibility=11

springVersion=5.1.3.RELEASE
springSecurityConfigVersion=5.1.2.RELEASE
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/alfio/config/DataSourceConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
Expand All @@ -49,7 +52,6 @@

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.EnumSet;
import java.util.Set;

Expand All @@ -69,12 +71,10 @@ public class DataSourceConfiguration implements ResourceLoaderAware {
@Bean
@Profile({"!"+Initializer.PROFILE_INTEGRATION_TEST, "travis"})
public PlatformProvider getCloudProvider(Environment environment) {
PlatformProvider current = PLATFORM_PROVIDERS
.stream()
.filter(p -> p.isHosting(environment))
.findFirst()
.orElse(PlatformProvider.DEFAULT);
return current;
return PLATFORM_PROVIDERS.stream()
.filter(p -> p.isHosting(environment))
.findFirst()
.orElse(PlatformProvider.DEFAULT);
}

@Bean
Expand Down Expand Up @@ -187,12 +187,12 @@ public void setResourceLoader(ResourceLoader resourceLoader) {
*/
private static class FakeCFDataSource extends AbstractDataSource {
@Override
public Connection getConnection() throws SQLException {
public Connection getConnection() {
return null;
}

@Override
public Connection getConnection(String username, String password) throws SQLException {
public Connection getConnection(String username, String password) {
return null;
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/alfio/config/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import alfio.util.DefaultExceptionHandler;
import com.openhtmltopdf.util.XRLog;
import org.apache.commons.lang3.Validate;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.web.context.ConfigurableWebApplicationContext;
Expand Down Expand Up @@ -70,8 +69,7 @@ public void onStartup(ServletContext servletContext) throws ServletException {
protected WebApplicationContext createRootApplicationContext() {
ConfigurableWebApplicationContext ctx = ((ConfigurableWebApplicationContext) super.createRootApplicationContext());
Objects.requireNonNull(ctx, "Something really bad is happening...");
ConfigurableEnvironment environment = ctx.getEnvironment();
this.environment = environment;
this.environment = ctx.getEnvironment();
return ctx;
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/alfio/config/MvcConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ public void addInterceptors(InterceptorRegistry registry) {
public HandlerInterceptor getEventLocaleSetterInterceptor() {
return new HandlerInterceptorAdapter() {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {

if(handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = ((HandlerMethod) handler);
RequestMapping reqMapping = handlerMethod.getMethodAnnotation(RequestMapping.class);

//check if the request mapping value has the form "/event/{something}"
Pattern eventPattern = Pattern.compile("^/event/\\{(\\w+)}/{0,1}.*");
Pattern eventPattern = Pattern.compile("^/event/\\{(\\w+)}/?.*");
if (reqMapping != null && reqMapping.value().length == 1 && eventPattern.matcher(reqMapping.value()[0]).matches()) {

Matcher m = eventPattern.matcher(reqMapping.value()[0]);
Expand All @@ -158,7 +158,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
String eventName = Optional.ofNullable(((Map<String, Object>)request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE)).get(val)).orElse("").toString();


LocaleResolver resolver = RequestContextUtils.getLocaleResolver(request);
LocaleResolver resolver = Objects.requireNonNull(RequestContextUtils.getLocaleResolver(request));
Locale locale = resolver.resolveLocale(request);
List<ContentLanguage> cl = i18nManager.getEventLanguages(eventName);

Expand All @@ -182,7 +182,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
public HandlerInterceptorAdapter getDefaultTemplateObjectsFiller() {
return new HandlerInterceptorAdapter() {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
Optional.ofNullable(modelAndView)
.filter(mv -> !StringUtils.startsWith(mv.getViewName(), "redirect:"))
.ifPresent(mv -> {
Expand Down Expand Up @@ -217,7 +217,7 @@ public void postHandle(HttpServletRequest request, HttpServletResponse response,
modelMap.putIfAbsent("paypalTestPassword", configurationManager.getStringConfigValue(alfio.model.system.Configuration.getSystemConfiguration(PAYPAL_DEMO_MODE_PASSWORD), "<missing>"));
}

modelMap.putIfAbsent(TemplateManager.VAT_TRANSLATION_TEMPLATE_KEY, TemplateManager.getVATString(event, messageSource, RequestContextUtils.getLocaleResolver(request).resolveLocale(request), configurationManager));
modelMap.putIfAbsent(TemplateManager.VAT_TRANSLATION_TEMPLATE_KEY, TemplateManager.getVATString(event, messageSource, Objects.requireNonNull(RequestContextUtils.getLocaleResolver(request)).resolveLocale(request), configurationManager));
});
}
};
Expand All @@ -234,7 +234,7 @@ private HandlerInterceptor getCSPInterceptor() {
return new HandlerInterceptorAdapter() {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
ModelAndView modelAndView) {

//
String reportUri = "";
Expand Down Expand Up @@ -272,7 +272,7 @@ public void postHandle(HttpServletRequest request, HttpServletResponse response,
public HandlerInterceptor getCsrfInterceptor() {
return new HandlerInterceptorAdapter() {
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
Optional.ofNullable(modelAndView).ifPresent(mv -> mv.addObject(WebSecurityConfig.CSRF_PARAM_NAME, request.getAttribute(CsrfToken.class.getName())));
}
};
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/alfio/config/RowLevelSecurity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
Expand All @@ -53,7 +54,7 @@ public class RowLevelSecurity {
new AntPathRequestMatcher("/authentication"));

private static boolean isCurrentlyInAPublicUrlRequest() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletRequest request = Objects.requireNonNull((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
return IS_PUBLIC_URLS.matches(request);
}

Expand Down Expand Up @@ -95,8 +96,8 @@ public RoleAndOrganizationsAspect(NamedParameterJdbcTemplate namedParameterJdbcT
public Object setRoleAndVariable(ProceedingJoinPoint joinPoint) throws Throwable {

if (isInAHttpRequest()) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
DataSource dataSource = jdbcTemplate.getJdbcTemplate().getDataSource();
HttpServletRequest request = Objects.requireNonNull((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
DataSource dataSource = Objects.requireNonNull(jdbcTemplate.getJdbcTemplate().getDataSource());
Connection connection = DataSourceUtils.getConnection(dataSource);

boolean mustCheck = false;
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/alfio/controller/EventController.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ public ValidationResult savePromoCode(@PathVariable("eventName") String eventNam
SessionUtil.cleanupSession(request);

Optional<Event> optional = eventRepository.findOptionalByShortName(eventName);
if(!optional.isPresent()) {
if(optional.isEmpty()) {
return ValidationResult.failed(new ValidationResult.ErrorDescriptor("event", ""));
}
Event event = optional.get();
ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
Optional<String> maybeSpecialCode = Optional.ofNullable(StringUtils.trimToNull(promoCode));
Optional<SpecialPrice> specialCode = maybeSpecialCode.flatMap((trimmedCode) -> specialPriceRepository.getByCode(trimmedCode));
Optional<SpecialPrice> specialCode = maybeSpecialCode.flatMap(specialPriceRepository::getByCode);
Optional<PromoCodeDiscount> promotionCodeDiscount = maybeSpecialCode.flatMap((trimmedCode) -> promoCodeRepository.findPromoCodeInEventOrOrganization(event.getId(), trimmedCode));

if(specialCode.isPresent()) {
if (!optionally(() -> eventManager.getTicketCategoryById(specialCode.get().getTicketCategoryId(), event.getId())).isPresent()) {
if (optionally(() -> eventManager.getTicketCategoryById(specialCode.get().getTicketCategoryId(), event.getId())).isEmpty()) {
return ValidationResult.failed(new ValidationResult.ErrorDescriptor("promoCode", ""));
}

Expand All @@ -157,14 +157,14 @@ public ValidationResult savePromoCode(@PathVariable("eventName") String eventNam
return ValidationResult.failed(new ValidationResult.ErrorDescriptor("promoCode", ""));
} else if (promotionCodeDiscount.isPresent() && isDiscountCodeUsageExceeded(promotionCodeDiscount.get())){
return ValidationResult.failed(new ValidationResult.ErrorDescriptor("usage", ""));
} else if(!specialCode.isPresent() && !promotionCodeDiscount.isPresent()) {
} else if(promotionCodeDiscount.isEmpty()) {
return ValidationResult.failed(new ValidationResult.ErrorDescriptor("promoCode", ""));
}

if(maybeSpecialCode.isPresent() && !model.asMap().containsKey("hasErrors")) {
if(!model.asMap().containsKey("hasErrors")) {
if(specialCode.isPresent()) {
SessionUtil.saveSpecialPriceCode(maybeSpecialCode.get(), request);
} else if (promotionCodeDiscount.isPresent()) {
} else {
SessionUtil.savePromotionCodeDiscount(maybeSpecialCode.get(), request);
}
return ValidationResult.success();
Expand All @@ -182,7 +182,7 @@ public String showEvent(@PathVariable("eventName") String eventName,

return eventRepository.findOptionalByShortName(eventName).filter(e -> e.getStatus() != Event.Status.DISABLED).map(event -> {
Optional<String> maybeSpecialCode = SessionUtil.retrieveSpecialPriceCode(request);
Optional<SpecialPrice> specialCode = maybeSpecialCode.flatMap((trimmedCode) -> specialPriceRepository.getByCode(trimmedCode));
Optional<SpecialPrice> specialCode = maybeSpecialCode.flatMap(specialPriceRepository::getByCode);

Optional<PromoCodeDiscount> promoCodeDiscount = SessionUtil.retrievePromotionCodeDiscount(request)
.flatMap((code) -> promoCodeRepository.findPromoCodeInEventOrOrganization(event.getId(), code));
Expand Down Expand Up @@ -302,19 +302,19 @@ public String handleCode(@PathVariable("eventName") String eventName, @PathVaria
if(res.isSuccess() && codeType == CodeType.PROMO_CODE_DISCOUNT) {
return redirectToEvent;
} else if (codeType == CodeType.TICKET_CATEGORY_CODE) {
TicketCategory category = ticketCategoryRepository.findCodeInEvent(event.getId(), trimmedCode).get();
TicketCategory category = ticketCategoryRepository.findCodeInEvent(event.getId(), trimmedCode).orElseThrow();
if(!category.isAccessRestricted()) {
return makeSimpleReservation(eventName, request, redirectAttributes, locale, null, event, category.getId());
} else {
Optional<SpecialPrice> specialPrice = specialPriceRepository.findActiveNotAssignedByCategoryId(category.getId()).stream().findFirst();
if(!specialPrice.isPresent()) {
if(specialPrice.isEmpty()) {
return redirectToEvent;
}
savePromoCode(eventName, specialPrice.get().getCode(), model, request.getRequest());
return makeSimpleReservation(eventName, request, redirectAttributes, locale, specialPrice.get().getCode(), event, category.getId());
}
} else if (res.isSuccess() && codeType == CodeType.SPECIAL_PRICE) {
int ticketCategoryId = specialPriceRepository.getByCode(trimmedCode).get().getTicketCategoryId();
int ticketCategoryId = specialPriceRepository.getByCode(trimmedCode).orElseThrow().getTicketCategoryId();
return makeSimpleReservation(eventName, request, redirectAttributes, locale, trimmedCode, event, ticketCategoryId);
} else {
return redirectToEvent;
Expand All @@ -339,7 +339,7 @@ public void calendar(@PathVariable("eventName") String eventName,
@RequestParam(value = "ticketId", required = false) String ticketId,
HttpServletResponse response) throws IOException {
Optional<Event> event = eventRepository.findOptionalByShortName(eventName);
if (!event.isPresent()) {
if (event.isEmpty()) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
Expand Down
Loading

0 comments on commit 8e1afd5

Please sign in to comment.