Skip to content

Commit

Permalink
Fix Freshmark compatibility with JDK 15+ (fixes #803)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-gentner-fnt committed Sep 4, 2022
1 parent 688e01a commit 225d992
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Objects;
Expand All @@ -31,6 +33,7 @@
import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.JarState;
import com.diffplug.spotless.Jvm;
import com.diffplug.spotless.Provisioner;
import com.diffplug.spotless.ThrowingEx.Supplier;

Expand All @@ -42,6 +45,10 @@ private FreshMarkStep() {}
private static final String DEFAULT_VERSION = "1.3.1";
private static final String NAME = "freshmark";
private static final String MAVEN_COORDINATE = "com.diffplug.freshmark:freshmark:";

private static final String NASHORN_MAVEN_COORDINATE = "org.openjdk.nashorn:nashorn-core:";

private static final String NASHORN_VERSION = "15.4";
private static final String FORMATTER_CLASS = "com.diffplug.freshmark.FreshMark";
private static final String FORMATTER_METHOD = "compile";

Expand All @@ -55,8 +62,15 @@ public static FormatterStep create(String version, Supplier<Map<String, ?>> prop
Objects.requireNonNull(version, "version");
Objects.requireNonNull(properties, "properties");
Objects.requireNonNull(provisioner, "provisioner");

List<String> mavenCoordinates = new ArrayList<>();
mavenCoordinates.add(MAVEN_COORDINATE + version);
if (Jvm.version() >= 15) {
mavenCoordinates.add(NASHORN_MAVEN_COORDINATE + NASHORN_VERSION);
}

return FormatterStep.createLazy(NAME,
() -> new State(JarState.from(MAVEN_COORDINATE + version, provisioner), properties.get()),
() -> new State(JarState.from(mavenCoordinates, provisioner), properties.get()),
State::createFormat);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,20 +15,16 @@
*/
package com.diffplug.spotless.markdown;

import static org.junit.jupiter.api.condition.JRE.JAVA_14;

import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.SerializableEqualityTester;
import com.diffplug.spotless.StepHarness;
import com.diffplug.spotless.TestProvisioner;

@EnabledForJreRange(max = JAVA_14)
class FreshMarkStepTest {
@Test
void behavior() throws Exception {
Expand Down

0 comments on commit 225d992

Please sign in to comment.